DEV Community

Caleb Zhao
Caleb Zhao

Posted on • Edited on

Incorrect calculations: tan(x) and cot(x) for large values of x

In this blog post, we explore incorrect calculations of the tangent function tan(x) and the cotangent function cot(x) for large numbers in MATLAB.

Example 1. Suppose x=235556677777.87. x=235556677777.87\,. Calculate tan(x) \tan(x) and cot(x) \cot(x) in MATLAB.

Let's just post the figure directly.

MATLAB outputFrom the above figure, it can be seen that the two outputs from MATLAB are
1.429064236906033 1.4290\red{64236906033} and 0.699758607188316. 0.69975\red{8607188316} .

However, the correct values with 16 significant digits are 0.1429079091621959e1 and 0.6997513334724058, respectively (as provided by ISRealsoft).

As a result, both outputs from MATLAB contain 11 incorrect digits, with an error rate of 11/16 = 68.75% for the significant figures.

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

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