Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I increase the number of digits in MATLAB?

Tags:

matlab

I realize this is a somewhat vague question so I'll do my best. If I have a number like n = 0.783325849821429, is there a way to display even more decimal places? This was produced with format long. The problem is that I'm doing error estimate calculations with sine and there comes a point where the estimation is so close to the actual value of sine that MATLAB calculates the error as 0, even though it's not possible that the estimation is completely accurate. There's always error, it's just too small for MATLAB to recognize. Is there a way to make MATLAB consider more decimal places?

like image 943
Aei Avatar asked Oct 14 '25 12:10

Aei


1 Answers

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 numbers in floating point.
You can test the machine precision using eps

eps( n )

If your estimate error is smaller than eps than your estimate is within machine precision and cannot be measured.

like image 154
Shai Avatar answered Oct 18 '25 01:10

Shai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!