FORTRAN: Differences between "cabs" and "csqrt"

  • Fortran
  • Thread starter Dimis414
  • Start date
  • Tags
    Fortran
In summary, using the CSQRT command will result in a complex vector with a non-negative real part, while using the CABS command will result in a real number with a non-negative value. This can lead to differences in the real parts of the complex numbers, especially when the argument is near π/2.
  • #1
Dimis414
6
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
  • #2
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..
 
  • #3
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:

Related to FORTRAN: Differences between "cabs" and "csqrt"

1. What is the difference between "cabs" and "csqrt" in FORTRAN?

"cabs" is a function in FORTRAN that calculates the absolute value of a complex number, while "csqrt" is a function that calculates the square root of a complex number.

2. Are there any similarities between "cabs" and "csqrt" in FORTRAN?

Both "cabs" and "csqrt" are functions that operate on complex numbers, and they can both be used to perform mathematical operations on these numbers.

3. Which function should I use to find the magnitude of a complex number in FORTRAN?

You should use the "cabs" function to find the magnitude of a complex number in FORTRAN, as it is specifically designed for this purpose.

4. Can I use "csqrt" to find the magnitude of a complex number in FORTRAN?

No, "csqrt" calculates the square root of a complex number, not the magnitude. To find the magnitude, you should use the "cabs" function.

5. Are there any performance differences between using "cabs" and "csqrt" in FORTRAN?

Since "cabs" and "csqrt" are both built-in functions in FORTRAN, there should not be a significant difference in performance between them. However, it is always a good idea to test and compare the performance of different functions for your specific code.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
4
Views
14K
Replies
0
Views
754
  • Programming and Computer Science
Replies
2
Views
4K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
6
Views
2K
Back
Top