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

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More