Logo

dev-resources.site

for different kinds of informations.

Incorrect calculations: tand(x) and cotd(x)

Published at
11/15/2024
Categories
errors
mtalab
testing
tan
Author
Caleb Zhao
Categories
4 categories in total
errors
open
mtalab
open
testing
open
tan
open
Incorrect calculations: tand(x) and cotd(x)

In this blog post, we explore incorrect calculations of the tangent function tand(x) and cotangent function cotd(x) of which the independent variable is in degrees in MATLAB.

Example 1. Given that x1 = 444555666.777 and x2=444555666.777e16, calculate tand(x1), cotd(x1), tand(x2), and cotd(x2).

Using MATLAB, I computed the values of tand(x) and cosd(x) at x1 and x2. The results are shown in the following screenshot.

MATLAB outputFrom the above screenshot, it can be seen that the outputs from MATLAB are āˆ’1.337846899312778,āˆ’0.747469684695369,āˆ’9.514364454222584, -1.337846899\red{312778}, -0.747469684\red{695369}, -\red{9.514364454222584},āˆ’1.337846899312778,āˆ’0.747469684695369,āˆ’9.514364454222584, and āˆ’0.105104235265676 -0.\red{105104235265676}āˆ’0.105104235265676 respectively.

However, the correct values, rounded to 16 significant digits, are -0.1337846899800357e1, -0.7474696844229537, -0.1732050807568877e1, and -0.5773502691896258, respectively (as provided by ISRealsoft).

Therefore, the error rates for the significant digits of the first two are 6/16 = 37.5% and 7/16 = 43.75%, respectively; while the last two have completely incorrect digits, resulting in an error rate of 100% for each.

previous

Featured ones: