DEV Community

Caleb Zhao
Caleb Zhao

Posted on

Incorrect calculations: sin(x) near x=k*π

In this blog post, we explore incorrect calculations of the sine function sin(x) in MATLAB near numbers around kπ(k0). k\,\pi (k\neq0).

Example 1. Given that x1=0.3769911184e212π x_1=0.3769911184\textup{e}2\approx 12\,\pi and
x2=0.166504e353π,x_2=0.166504\textup{e}3\approx 53\,\pi\,, calculate sin(x1) \sin(x_1) and sin(x2) \sin(x_2) in MATLAB.

Let's just post the figure directly.

MATLAB outputFrom the above screenshot, it can be seen that the two outputs from MATLAB are
3.077518377555020e09 -3.077518\red{377555020}e-09 and 4.106402475102297e04. 4.106402475\red{102297}e-04.

However, the correct values with 16 significant digits are -0.3077518861551721e-8 and 0.4106402475009074e-3, respectively (as provided by ISRealsoft).

Thus, the outputs of MATLAB contain 9 and 6 incorrect digits, with error rates of 9/16 = 56.25% and 6/16 = 37.5% respectively for the significant figures.

previous \,\quad\quad\quad\quad\hspace{7.2cm} next

Top comments (0)