sin(x)^2+cos(x)^2 = 1 on different calcs
|
09-24-2018, 02:05 PM
Post: #1
|
|||
|
|||
sin(x)^2+cos(x)^2 = 1 on different calcs
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. The interesting thing is that Python, Prime and Free42 give different results, and the ‘errors’ occur at different points, presumably due to the different math/floating point engines. The only calc that had no errors was Free42, which gave 1 in all cases. Hp Prime Code:
Gives 1 for all values except 1, 6, 7, 9 where it gives 0.999999999999 as the answer. Python Code:
Gives: Code:
Reassuringly, Free42 gives 1 in all cases. I used my python to rpn converter https://pyrpn.herokuapp.com to create the Free42 program, since I already had the Python code worked out. I just had to move the for loop before the sincos function, and change math.sin to SIN. Code:
Code:
which when run, shows 1 in all cases, and if virtual printing is on with PON you get to see the list of values on the virtual printer tape, confirming this. An interesting evening’s research :-) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)