Matlab sin(pi) and its relation to machine epsilon
Asked Answered
L

2

7

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

Luke answered 11/1, 2017 at 7:10 Comment(5)
don't be frustrated. you are not foolish. this is not an easy subject to grasp.Overwrought
I'm not sure how that question can be considered a duplicate.Splendor
@Overwrought I agree with Simon. OP explicitly asks for an explanation of the machine epsilon, specifically the eps function, which is not the topic of the other question.Footsore
Maybe this explanation of the machine epsilon is helpful: https://mcmap.net/q/1627770/-how-to-calculate-machine-epsilon-in-matlabFootsore
Ask yourself something: What's the next number after 1.0? Is it 1.00001? 1.000000001? 1.000000000000001? As you see you cannot have ALL numbers represented, so the step between one number and the next one is eps (which as you can see is a pretty small number (1.7764e-15)Commendam
S
1

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 ≈ 2.22 × 10-16

|pi - π| ≈ 1.22 × 10-16

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

sin(pi) = | sin(pi) - sin(π) | ≈ |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.

Splendor answered 11/1, 2017 at 12:34 Comment(0)
O
1

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.

Ortegal answered 11/1, 2017 at 11:37 Comment(0)
S
1

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 ≈ 2.22 × 10-16

|pi - π| ≈ 1.22 × 10-16

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

sin(pi) = | sin(pi) - sin(π) | ≈ |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.

Splendor answered 11/1, 2017 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.