In this blog post, we explore incorrect calculations of the sine function sind(x) and cosine function cosd(x) of which the independent variable is in degrees in MATLAB.
Example 1. Given that x1 = 12345678.9 and x2=12345678.9e20, calculate sind(x1), cosd(x1), sind(x2), and cosd(x2).
Using MATLAB, I computed the values of sind(x) and cosd(x) at x1 and x2. The results are shown in the following screenshot.
From the above screenshot, it can be seen that the outputs from MATLAB are and respectively.
However, the correct values for the first two, rounded to 16 significant digits, are -0.3239174181981494 and -0.9460853588275453, respectively; the accurate values for the last two are 0 and 1, respectively (as provided by ISRealsoft).
Therefore, the error rates for the significant digits of the first two are 7/16 = 43.75% and 5/16 = 31.25%, respectively; while the last two have completely incorrect digits, resulting in an error rate of 100% for each.
Top comments (0)