DEV Community

Caleb Zhao
Caleb Zhao

Posted on

Incorrect calculations: sec(x) and csc(x) for large values of x

In this blog post, we explore incorrect calculations of the secant function sec(x) and cosecant function csc(x) for large numbers in MATLAB.

Example 1. Given that x = 1234567890888777.123, calculate sec(x) and csc(x).

Using MATLAB, I computed the values of sec(x) and csc(x) at x = 1234567890888777.123. The result is shown in the following screenshot.

MATLAB outputFrom the above screenshot, it can be seen that the outputs from MATLAB are 1.059606794245841 -1.\red{059606794245841} and 3.024159505568874 -\red{3.024159505568874} respectively.

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

Therefore, out of the 32 significant digits in the two outputs from MATLAB, only 1 digit is correct. The error rates are 15/16 = 93.75% and 16/16 = 100%, respectively.

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

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay