Asked by Yakub Shalmiyev
on 15 Sep 2018 at 22:11

I don't understand how I would estimate an absolute error of matlabs' stored value of pi. From what I understand, 16 digits are displayed, but is that what is stored? I'm trying to take those 16 digits as the result value, and use "Pi" as the true value when I compute absolute error. But what I get isn't the answer, as it should be C * 10^-16 , where c is the answer.

What I really don't get is, isn't this a really stupid question? We rely on computers to generate the next new digits of pi, or the next largest prime number. How is it even possible to take a never-ending value (which we receive from computer code) and find the absolute error (using the same coding platform?)

Answer by Walter Roberson
on 16 Sep 2018 at 5:48

Accepted Answer

If you have a finite approximation, then you cannot find the absolute error relative to an irrational value: you can only find **bounds** on the absolute error.

The actual value stored is

>> fprintf('%.999g\n', pi) 3.141592653589793115997963468544185161590576171875

However, you would need to be using a Mac to get this exact value with that command. The Windows libraries are quite broken for this purpose; the Linux libraries are less broken but still cannot display exact value. For Windows or Linux, you should probably grab https://www.mathworks.com/matlabcentral/fileexchange/22239-num2strexact-exact-version-of-num2str

Without that contribution, you could still use

>> num2hex(pi) ans = '400921fb54442d18'

and then analyze the IEEE 754 representation given there. This shows you the hex version of the exact bit pattern used. You might want to try it on your own system: if it gives you the same hex then you can rely upon the decimal value that I posted.

If you have the symbolic toolbox, then

>> vpa(sym(pi,'f'),50) ans = 3.141592653589793115997963468544185161590576171875

which shows the exact value stored.

>> vpa(pi,100) ans = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068

which shows pi itself rounded to 100 digits.

The symbolic toolbox recognizes the bit pattern for the numeric value stored in pi and typically converts it to the internal symbol representing the irrational number. You can be extra careful with that by using sym('pi') instead of pi

Yakub Shalmiyev
on 16 Sep 2018 at 20:19

Thanks for helping me out again, Walter.

I have one question for you, why does this command show the stored value?

>> vpa(sym(pi,'f'),50)

I understand that 52 bits are stored for 16 digits, 11 bits for 2^E, and 1 bit for the sign. How does this come into play here?

Walter Roberson
on 16 Sep 2018 at 21:22

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.