How to increase the number of digits in MATLAB?
I realize this is a somewhat vague question, so I'll do my best. If I have a number like this n = 0.783325849821429
, is there a way to show even more decimal places? This was done with a long format. The problem is that I am doing calculations with an error estimate with sine, and there comes a point where the estimate is so close to the actual sine value that MATLAB calculates the error as 0, although it is impossible for the estimate to be completely accurate. There is always an error, it is too small for MATLAB to recognize. Is there a way to make MATLAB more decimal places?
source to share
You can always ask for more digits using formatted strings
fprintf(1, 'n = %.20f\n', n ); % print with 20 digits after the decimal point
However, there is a limit to the precision of stored floating point numbers.
You can check the accuracy of the machine usingeps
eps( n )
If your estimate error is less eps
than your estimate is within the machine's precision and cannot be measured.
source to share
if you use vpa function to improve precision then it will have your variable as syms and after that if you want to use this variable for other internal Matlab functions then it won't work so find another way.
eg.
a=vpa(a,5)
a =
[ 1.25, 2.0276, 3.2108, 3.3695, 2.0589, 1.0]
polyval(a,3)
??? Undefined function or method 'isfinite' for input arguments of type
'sym'.
Error in ==> polyval at 54
if isscalar(x) && (nargin < 3) && nc>0 && isfinite(x) &&
all(isfinite(p(:)))
source to share