ATAN(3) - [MATHEMATICS:TRIGONOMETRIC] Arctangent AKA inverse tangent function
result = atan(x) | atan(y, x)
elemental TYPE(kind=KIND) function atan(y,x)TYPE(kind=KIND),intent(in) :: x TYPE(kind=KIND),intent(in),optional :: y
o If Y is present X and Y must both be real. Otherwise, X may be complex. o KIND can be any kind supported by the associated type. o The returned value is of the same type and kind as X.
ATAN(X)(3) returns the inverse tangent (ie. arctangent) of the elements of X in radians. The function accepts both real and complex inputs, and is elemental (therefore allowing arguments to be scalar, vector, or matrix). The atan operation is performed element-wise when X is nonscalar.
o For real values of X, atan(X) returns values in the interval [-PI/2, PI/2]. o For complex values of X, atan(X) returns complex values. When x is complex, Fortran’s intrinsic ATAN(x) computes the principal value of the complex arctangent function and returns a complex number in radians. The Imaginary part is an unbounded real value representing the hyperbolic growth of the inverse function.When Y is not supplied the inverse tangent is defined as- Converts complex coordinates using the natural logarithm and imaginary unit. - Reduces to the standard real arctangent when the input has a zero imaginary component. - Undefined at the exact poles. - Branch cuts lie along the outer imaginary axis
i=sqrt(-1) atan(z)=>(i/2)*log(i+z/i-z).This definition of the atan function returns angles in radians within the interval [-PI/2, PI/2]. To find the four-quadrant inverse tangent, where the returned angles are in the interval [-PI, PI], supply the Y value or equivalently, use atan2(3).
o X : The value to compute the arctangent of. if Y is present, X shall be real. o Y : is of the same type and kind as X. If X is zero, Y must not be zero.
The returned value is of the same type and kind as X. If Y is present, the result is identical to ATAN2(Y,X). Otherwise, it is the arc tangent of X, where the real part of the result is in radians and lies in the range -PI/2 <= ATAN(X) <= PI/2
Sample program:
program demo_atan use, intrinsic :: iso_fortran_env, only : real32, real64, real128 implicit none character(len=*),parameter :: g=(*(g0,1x)) real(kind=real64),parameter :: & Deg_Per_Rad = 57.2957795130823208767981548_real64 real(kind=real64) :: x real(kind=real64),parameter :: &Results:xvals(*)=[2.0d0, 2.0d0, 2.0d0, 2.0d0, -2.0d0, -2.0d0, -2.0d0, -2.0d0 ] real(kind=real64),parameter :: & yvals(*)=[2.0d0, 2.0d0, -2.0d0, -2.0d0, 2.0d0, 2.0d0, -2.0d0, -2.0d0 ] ! ! basics ! ! with just a real X returns angles in radians ! in the interval [-PI/2, PI/2]. x=2.866_real64 print g, atan(x) ! ! all the quadrants using two arguments ! print g, atan( 2.0d0, 2.0d0),atan( 2.0d0, 2.0d0)*Deg_Per_Rad print g, atan( 2.0d0,-2.0d0),atan( 2.0d0,-2.0d0)*Deg_Per_Rad print g, atan(-2.0d0, 2.0d0),atan(-2.0d0, 2.0d0)*Deg_Per_Rad print g, atan(-2.0d0,-2.0d0),atan(-2.0d0,-2.0d0)*Deg_Per_Rad ! ! elemental ! print g, elemental: print g, atan(xvals,yvals)*Deg_Per_Rad print g, elemental: ! ! when x and y are present, atan(3) is an alias for atan2(2) ! print g, For comparison to atan2(3): print g, atan2(xvals,yvals)*Deg_Per_Rad print g, test1 ,merge(PASSED,FAILED, & & all(atan(xvals,yvals)==atan2(xvals,yvals))), & & atan(xvals,yvals)==atan2(xvals,yvals)
end program demo_atan
> 1.235085437457879 > .7853981633974483 45.00000000000000 > 2.356194490192345 135.0000000000000 > -.7853981633974483 -45.00000000000000 > -2.356194490192345 -135.0000000000000 > elemental: > 45.0000000000000 45.0000000000000 135.000000000000 135.000000000000 > -45.0000000000000 -45.0000000000000 -135.000000000000 -135.000000000000 > For comparison to atan2(3): > 45.0000000000000 45.0000000000000 135.000000000000 135.000000000000 > -45.0000000000000 -45.0000000000000 -135.000000000000 -135.000000000000 > test1 PASSED T T T T T T T T
FORTRAN 77 for a complex argument; and for two arguments Fortran 2008
ATAN2(3), TAN(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
o wikipedia: inverse trigonometric functions
