Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Machine epsilon of the Micromite
Author | Message | ||||
cdeagle Senior Member Joined: 22/06/2014 Location: United StatesPosts: 261 |
Here's a short program that determines the machine epsilon of the Micromite running version 4.6B. Machine epsilon can be defined several ways; (1) that number, when added to one, is still one (according to the computer). (2) the distance from 1.0 to the next largest floating point number. Machine epsilon is important in numerical analysis because it can be used to "control" the number of iterations (convergence) of an algorithm. The square root of epsilon is often used for the convergence criterion of an iterative number method. It's also an indication or guideline when looking for a "reasonable" answer without spending lots of CPU cycles to gain very little in the final result. ' determine Micromite machine epsilon
x = 1.0 DO WHILE ((1.0 + x) > 1.0) x = x/2.0 PRINT "x = ", x LOOP PRINT " " PRINT "machine epsilon = ", x END Here are the results. RUN
x = 0.5 x = 0.25 x = 0.125 x = 0.0625 x = 0.03125 x = 0.015625 x = 0.0078125 x = 0.00390625 x = 0.00195312 x = 0.000976563 x = 0.000488281 x = 0.000244141 x = 0.00012207 x = 6.10352e-05 x = 3.05176e-05 x = 1.52588e-05 x = 7.62939e-06 x = 3.81470e-06 x = 1.90735e-06 x = 9.53674e-07 x = 4.76837e-07 x = 2.38419e-07 x = 1.19209e-07 x = 5.96046e-08 machine epsilon = 5.96046e-08 |
||||
srnet Senior Member Joined: 08/08/2014 Location: United KingdomPosts: 164 |
How can 1 and a floating point number have distance ? $50SAT is Silent but probably still working. For information on LoRa visit http://www.loratracker.uk/ |
||||
shoebuckle Senior Member Joined: 21/01/2012 Location: AustraliaPosts: 189 |
Pure mathematics is indeed a mystery unto itself. Not of great use to us mortals but it came in handy to prove Fermat's Last Theorum! |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3677 |
Except this is Applied Mathematics and of real importance. John |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1085 |
Distance as in how far apart. Micromite floating point numbers are represented by 32 bits (is that right?) so epsilon represents the difference to the next discrete value. 1.0000000000000 is followed by 1.0000000596046 if I've got my decimal places right. Which means for example that the number 1.0000000298000 cannot be represented by the Maximite. I don't have a Micromite setup so I can't test if epsilon is the same if calculated differently, for example, by dividing by, say, 1.9, instead of 2.0 Visit Vegipete's *Mite Library for cool programs. |
||||
cdeagle Senior Member Joined: 22/06/2014 Location: United StatesPosts: 261 |
"What good are numbers?" asked the plumber. "What good is a 1 1/2 inch P-trap when I need a 1 1/4 inch P-trap?" replied the mathematician. CORRECTION: Because of the way the DO WHILE loop executes in the source code example at the beginning of this post, the machine precision should be 1.19209e-07. The math implementation on a micro-controller and most CPUs is a function more of the software used to calculate than the hardware. For example, the epsilon for double precision is typically 2.23...e-16. When calculated in MATLAB, the double precision epsilon is the same for both 32-bit and 64-bit versions of Windows 7. This is also true for both 32-bit and 64-bit versions of MATLAB. Math calculations in most modern Intel CPUs is now performed in hardware using a floating point unit (FPU). For a micro-controller example, the machine epsilon for the the EzSBC1 controller is 2.23....e-16. This 32-bit CPU uses IEEE 64-bit math in the Control BASIC firmware. To visualize distance between numbers, image you are on the equator walking east or west. The machine epsilon is the distance you would have to walk before the computer realizes you have actually moved. Physically, this distance could be feet, meters or any other useful measure. IMHO, there seems to be a "time constant" between mathematics and society. It may be many years between the invention of a new mathematical concept or theory and the actually use of "new math" by society. Hope this helps. |
||||
G8JCF Guru Joined: 15/05/2014 Location: United KingdomPosts: 676 |
With Windows 7 x64 in VB.NET I get Single precision machine epsilon = 1.110223E-16
Double precision machine epsilon = 1.11022302462516E-16 Module MachineEpsilon Sub Main() Dim x As Double ' determine Micromite machine epsilon x = 1.0 Do While ((1.0 + x) > 1.0) x = x / 2.0 Console.WriteLine("x = " & x) Loop Console.WriteLine(" ") Console.WriteLine("machine epsilon = " & x) End Sub End Module Maths underpins our understanding of the real world. Without it we'd be still praying to statues, sacrificing animals, reading tea-leaves ... Peter The only Konstant is Change |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1139 |
Maths underpins our understanding of the real world. Without it we'd be still praying to statues, sacrificing animals, reading tea-leaves ... Peter what is wrong about sacrificing animals? Regards Michael |
||||
isochronic Guru Joined: 21/01/2012 Location: AustraliaPosts: 689 |
(Please forgive typos, black text on a wjite bacground is almost invisible to me ) [EDIT] I alaways thought the epsilon was the smallest number so ..I thought this would be equivalent...but ..obviously not ! Why is it so different ? ]>L
PROGRAM epsilon C DOUBLE a FORMAT (E10.8,/) a = 1.0 DO WHILE ( a > 0.0 ) WRITE (6,0) a a = a / 2.0 END DO END \ 1.00000000e+00 5.00000000e-01 2.50000000e-01 1.25000000e-01 ... 1.01184644e-320 5.05923221e-321 2.52961611e-321 1.26480805e-321 6.32404027e-322 3.16202013e-322 1.58101007e-322 7.90505033e-323 3.95252517e-323 1.97626258e-323 9.88131292e-324 4.94065646e-324 BTW for plotting data it may be worth the TeraTerm Tektronix 4010 emulation. Kind of ancient but.. ripple from plugpak ,, and a faster AD run , looking at 9600 rs232 The slow scan used this code or very similar, the TX routines are small and straightforward PROGRAM sdisto C INTEGER*2 dat(256) CALL tekinit ( ) CALL tekrect ( ) CALL acquiredat ( dat ) CALL tekplot ( dat ) PRINT *, C END C SUBROUTINE acquiredat ( acdat ) INTEGER*4 i DO 20 i = 1, 256 20 acdat(i) = ADX5 RETURN END C C SUBROUTINE tekinit ( ) TXINIT RETURN END C C SUBROUTINE tekrect ( ) TXMOVE 32, 250 TXDRAW 544, 250 TXDRAW 544, 762 TXDRAW 32, 762 TXDRAW 32, 250 RETURN END C SUBROUTINE tekplot ( dat ) INTEGER*4 i, j INTEGER*2 nn, mm nn = 32 mm = dat(1) / 2 + 250 IF ( mm > 762 ) mm = 762 TXMOVE nn, mm DO 40 i = 2, 256 nn = nn + 2 mm = dat(i) / 2 + 250 IF ( mm > 762 ) mm = 762 TXDRAW nn, mm 40 CONTINUE TXMOVE 32, 250 RETURN END \ |
||||
isochronic Guru Joined: 21/01/2012 Location: AustraliaPosts: 689 |
D'OH !! It says, "when added to one "... and doing so, I get the dp epsilon OK.. The difference being, one quantity is the smallest number that can be compared to zero whereas the other is the smallest that can be used with the precision specified...went right past it |
||||
Print this page |