In Fortran, the ATAN2() function can be used to calculate the arctangent of the ratio of two numbers. The ATAN2() function takes two arguments, representing the y-coordinate and x-coordinate, and returns the angle in radians.
Example
program atan2_example
real :: x, y, result
x = 1.0
y = 1.0
result = ATAN2(y, x)
write(*,*) "The arctangent of (", y, "/", x, ") is", result
end program atan2_example
Output
The arctangent of ( 1.00000000 / 1.00000000 ) is 0.785398185
We calculate the arctangent of the ratio y/x using ATAN2(y, x).
The result is stored in the variable result and then printed to the console using the write statement.
Note:
- Keep in mind that the ATAN2() function returns the angle in radians.
- If you want the result in degrees, you can convert it using program Radian to Degree – FORTRAN