Reputation: 7449
I think There is something wrong in Matlab relative to the number of decimal places used to display the number e. If put
>> sprintf('%.30f',exp(1))
ans =
2.718281828459045500000000000000
enter code here
I think this is wrong because The number and contains an infinite number of decimal places instead of just the 16 that matlab show in this example. Does anyone know how I can get better accuracy using Matlab? Thank you.
Upvotes: 1
Views: 362
Reputation: 2401
Some additional information on double precision and MATLAB.
In the full IEEE system, this spacing is 2- 52. MATLAB calls this quantity eps, which is short for machine epsilon.
eps = 2^(–52)
Before the IEEE standard, different machines had different values of eps. The approximate decimal value of eps is 2.2204 • 10-16. Either eps/ 2or eps can be called the roundoff level. The maximum relative error incurred when the result of a single arithmetic operation is rounded to the nearest floating-point number is eps/ 2. The maximum relative spacing between numbers is eps. In either case, you can say that the roundoff level is about 16 decimal digits.
Upvotes: 3
Reputation: 272467
No, there is not a bug.
By default, numbers in Matlab are represented by double-precision floating point. These have 52 bits of mantissa, which is approximately equivalent to 16 significant figures. Asking Matlab to print out more decimal places will not magically create more precision.
It's very unlikely you will need more precision than this.
Upvotes: 10
Reputation: 49311
Matlab uses IEEE double precision, so that's as good as you will get for vanilla Matlab.
http://www.mathworks.com/support/solutions/en/data/1-1AGHW/?solution=1-1AGHW suggests getting the Symbolic Math Toolbox, which supports variable precision arithmetic. Or use another tool such as Maple.
Upvotes: 4