We observed the following while experimenting on MATLAB pi

We observed the following while experimenting on MATLAB

pi = 3.141592653589793 sin(pi) = 1.224646799147353e-16 cos(pi) = -1

Explain why in MATLAB, sin() = 0, while cos() = 1.

Solution

It is impossible for \'cos\' and \'sin\' to return the exactly correct values for angles which are only rational approximations to pi/2 and pi, respectively, because the exact answers would themselves be irrational.
But correct in the sense that those values are the correct floating point values for the sin and cos of the floating point approximations to pi/2 and -pi.

The pi in matlab is not a real \'pi\',but it is only a floating-point number close to \'pi\'.
Trigonometric functions around pi may have errors close to machine precision.

These unwanted results do not come from function evaluations. It is because pi value cannot be represented in floating-point number.

We observed the following while experimenting on MATLAB pi = 3.141592653589793 sin(pi) = 1.224646799147353e-16 cos(pi) = -1 Explain why in MATLAB, sin() = 0, wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site