Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab sin(pi) and its relation to machine epsilon

I understand that the reason why sin(pi) is not equal to zero is because of the fact that there is not enough bits to store all the significant digits of "pi", but what does that have to do with machine epsilon?

I read online what machine epsilon was, but after an hour of reading various definitions worded differently I got confused and did not understand the concept of epsilon. I ended up getting really frustrated in my own foolishness...

This following example was given in the MATLAB documentation and I don't understand it, can someone explain to me what the example is trying to show?

Find the distance from 10.0 to the next largest double-precision number.

d = eps(10.0)

d =

   1.7764e-15

http://www.mathworks.com/help/matlab/ref/eps.html

like image 222
Belphegor Avatar asked Jan 11 '17 07:01

Belphegor


Video Answer


2 Answers

There are a couple of different definitions of machine epsilon, but Matlab eps is fairly typical, being the gap between 1.0 and the next largest double precision floating point number.

We can actually make this more general: for any floating point number between 2kx < 2k+1, the gap between x and the next largest floating point number is 2k × eps (i.e. eps(x) in Matlab). Moreover, the gap between any real number and its nearest floating point approximation is half this.

Since 2 ≤ π < 4;, this means that the gap between pi (the numerical approximation) and π (the exact irrational number) is bounded by eps. In actual fact, it is just over half that:

eps &approx; 2.22 × 10-16

|pi - π| &approx; 1.22 × 10-16

Now using the result from @aka.nice answer, and that sin(π) = 0, we have that

sin(pi) = | sin(pi) - sin(π) | &approx; |pi - π| < eps

i.e. it is also bounded by eps.

Note: there is also some slight rounding between sin(pi) (the numeric result) and sin(pi) (the exact result), but this is of order eps2, so can be ignored in this case.

like image 182
Simon Byrne Avatar answered Sep 22 '22 01:09

Simon Byrne


At first order, sin(pi-epsilon)=epsilon+O(epsilon^3)

So, if we have an approximated value of pi instead of pi (with an error up to 1/2 unit of least precision), then we expect this error to be transferred directly to the sine result.

Machine epsilon is definitely related to the error we make with approximated value of pi.

like image 29
aka.nice Avatar answered Sep 25 '22 01:09

aka.nice