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

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please consider leaving a ❤️ or a kind comment on this post if it was useful to you!

Join our community and unlock a world of knowledge and shared experiences!