DEV Community

Caleb Zhao
Caleb Zhao

Posted on • Edited on

Incorrect calculations: tan(x) and cot(x) near x=k*π+π/2

Exploring the computational errors of the tangent function tan(x) and cotangent function cot(x) in MATLAB near numbers around kπ+π2. k\,\pi+\frac{\pi}{2}.

Example 1. Suppose x=39.2699081712π+π2. x=39.26990817\approx12\,\pi+\frac{\pi}{2}. Calculate tan(x) \tan(x) and cot(x) \cot(x) in MATLAB.

Let's just post the picture directly.

MATLAB outputHowever, the correct values with 16 significant digits are -0.7837941516239115e10 and -0.1275845192169577e-9, respectively (as provided by ISRealsoft).
Thus, the output of MATLAB contains only 4 and 5 correct digits, with error rates of (16-4)/16 = 75% and (16-5)/16 = 68.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