DEV Community

Caleb Zhao
Caleb Zhao

Posted on • Edited on

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

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

Example 1. Given that x1=0.942477796123e13π x_1=0.942477796123\textup{e}1 \approx 3\,\pi and
x2=0.7853981633974e225π,x_2=0.7853981633974\textup{e}2 \approx 25\,\pi\,, calculate csc(x1) \csc(x_1) and csc(x2) \csc(x_2) in MATLAB.

Using MATLAB, we computed the values of csc(x1) \csc(x_1) and csc(x2). \csc(x_2). The result is shown in the following screenshot.

MATLAB outputFrom the above screenshot, it can be seen that the outputs from MATLAB are
2.170988725424315e+09-2.17098\red{8725424315}\textup{e}+09 and 2.069879330499836e+11 2.069\red{879330499836}\textup{e}+11 , respectively.

However, the correct values with 16 significant digits are -0.217098558923038e10 and 0.2069981278717736e12, respectively (as provided by ISRealsoft).

Thus, the output of MATLAB contains only 6 and 4 correct digits, with error rates of (16-6)/16 = 62.5% and (16-4)/16 = 75% respectively for the significant figures.

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more