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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Retry later