Post Reply 
sin(x)^2+cos(x)^2 = 1 on different calcs
09-24-2018, 07:09 PM (This post was last modified: 09-24-2018 07:11 PM by Dieter.)
Post: #6
RE: sin(x)^2+cos(x)^2 = 1 on different calcs
(09-24-2018 02:05 PM)tcab Wrote:  I’ve just been playing around with truism that sin(x)^2+cos(x)^2 = 1.

I ran a loop checking this for different values of x on different calcs, incl Python. Let’s say x ranges from 0..20.

I expected the result to be 1 in all cases but of course such is the nature of floating point that some results are 1 or 0.999999999999 or 1.0000000000000002 thus disappointingly, not exactly 1 in all cases.

There is nothing to be disappointed about. On the contrary, you should be glad that the result is not (!) 1 in all cases.

Consider the case sin(6°) and cos(6°).

sin(6°) = 0,104528463267653...
cos(6°) = 0,994521895368273...

Any decent 12-digit calculator should return 0,104528463268 and 0,994521895368. The square of the sine is not much of a problem here. But since the cosine is rounded down, its square is also slightly below the true value, and here it shows in the 12 digit:

0,994521895368^2 = 0,989073800366359... or 0,989073800366 (rounded to 12 digits)
while the true value is
0,994521895368273...^2 = 0,989073800366902... or 0,989073800367 with 12-digit precision.

So there are cases where the errors due to rounding to a given number of places compensate each other, while in others they add up and so they show up in the result. It simply depends on how the first discarded digit rounds. Both in the sine and cosine as well as in their squares.

If a calculator actually returned 1 exactly in all cases I'd be concerned about its accuracy. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: sin(x)^2+cos(x)^2 = 1 on different calcs - Dieter - 09-24-2018 07:09 PM



User(s) browsing this thread: 2 Guest(s)