Fortran FORTRAN: Differences between "cabs" and "csqrt"

  • Thread starter Thread starter Dimis414
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
The discussion highlights the differences between the FORTRAN commands CSQRT and CABS when applied to complex vectors. CSQRT(cvect1**2 + cvect2**2 + cvect3**2) yields a complex number with both real and imaginary parts, while CABS(cvect1 + cvect2 + cvect3) returns only the real part, which is the absolute value of the sum. Although the real parts from both commands can be close, they are not identical due to the distinct mathematical operations they perform. The CSQRT function always returns a complex number with a non-negative real part, whereas CABS provides a non-negative real value. Significant differences in their outputs can occur when the input arguments approach π/2.
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?
 
Technology 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:
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
14K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K