FORTRAN: Differences between "cabs" and "csqrt"

  • Context: Fortran 
  • Thread starter Thread starter Dimis414
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
Dimis414
Messages
6
Reaction score
0
Assumung adding 3 complex vectrors (cvect1, cvect2 and cvect3).
What is the difference between using command:
CSQRT(cvect1**2+cvect2**2+cvect3**2)
and command:
CABS(cvect1+cvect2+cvect3)
??
The first one produces a complex vector (real and imaginary part), but the second only the real part has a value (the imaginary is zero).
However, both the real parts are pretty close but not the same. Why is that?
 
Physics news on Phys.org
Dimis414 said:
Assumung adding 3 complex vectrors (cvect1, cvect2 and cvect3).
What is the difference between using command:
CSQRT(cvect1**2+cvect2**2+cvect3**2)
and command:
CABS(cvect1+cvect2+cvect3)
??
The first one produces a complex vector (real and imaginary part), but the second only the real part has a value (the imaginary is zero).
However, both the real parts are pretty close but not the same. Why is that?
It's the difference between the complex square root and the absolute value (or magnitude) of a complex number. The square root of a complex number is also complex. The abs. value of a complex number is a real number..
 
Dimis414 said:
However, both the real parts are pretty close but not the same. Why is that?
That is just a coincidence. The real values can be completely different. The absolute value will always be a non-negative real, but the square root can have a negative real part.

CORRECTION: FORTRAN CSQRT always return a complex number with a non-negative real part.
So to get a real part very different from CABS, the input would need to have argument near π/2. In that case, the real part would be a relatively small positive number.
 
Last edited: