Reputation: 7759
I'm getting some strange behavior using COS() and SIN() libraries in Fortran 77. It picks what number to perform it's operation on like here :
DATA V , THETA , PI / 100 , 45 , 3.1416 /
THETA = THETA * PI/ 180.0
PRINT *, "THETA = " , THETA
VX = V * COS ( THETA )
VY = V * SIN ( THETA )
PRINT *, VX , VY
END
when i check it, i find that
COS(THETA) = COS(45)
not
COS(0.7853)
and the same goes to SIN() too. So why does this happen ?
This is my output :
THETA = 0.785400
70.7105 70.7108
Upvotes: 0
Views: 3499
Reputation: 182782
Those are the correct results. You're taking the cos of 45 degrees (converted to radians) and multiplying it by 100, and the cos of 45 degrees (or pi/4 radians) is 0.7071067, and so the expected value to print out is 70.7106.
SIN and COS functions take the arguments in radians. You use the correct formula to convert the input values from degrees to radians, and it's giving you the correct results for those converted values.
I'm curious how you could do the right conversion, and not realize that you did the right thing and got the right answer. Did you take this code from somewhere else?
Upvotes: 2