madking153 said:
hi, how to determine the machine precision in MATLAB and estimate from this how many bits are used in the mantissa ??
OK, since no one tackled this, I will.
This is not restricted to just using Matlab, but I think you can write your own routine in matlab.
The common way of determining machine precision (some call it the machine epsilon) is the figure out when a mathematical operation hasn't changed when two different numbers are used that only differ by a very small amount (thus the term machine "epsilon"). For example, write a routine like this:
1. x = 1.0
2. x = (x/2) + 1.0
3. If x > 1.0, go do (2) again
It will continue to do the loop until x is small enough that when you add it to 1.0, the machine no longer sees it as any different than 1.0. Try this with a few times with x defined with several different precision. The smallest value of x upon exiting the loop is your machine epsilon.
Now, what is interesting also is that you MAY get a different value for the machine epsilon if you do this instead:
1. x = 1.0
2. x = x/2
3. If x > 0, go do (2) again
At first glance, there shouldn't be any different between these two routines, but it depends on how the machine or register compares a value with the value "0". You get a smaller machine epsilon using this routine. However, I don't think this is a safe lower limit to use, since most of the time, you are actually doing mathematical operations. So the earlier machine epsilon will be the one to trust.
Zz.