abs
Absolute value of a complex number
Description
The abs function returns the absolute value of the complex number . The result is the real number denoted by and defined through:Example:
Example - Abs
Problem
This program returns the absolute value of the complex number z=0.5+2i.
Workings
#include <stdio.h> #include <complex> using std::complex; int main() { complex<double> z; z=0.5+2i; printf("|0.5 + 2 i| = %.4lf\n", abs(z)); return 0; }
Solution
Output:
|0.5 + 2 i| = 2.0616