The C++ std::complex::norm() function is used to return the squared magnitude of the complex number, calculated as the sum of the squares of its real and imaginary parts. For example, a=x+yi, where x and y are real and imaginary numbers, then the norm is calculated as a2+b2.
SyntaxFollowing is the syntax for std::complex::norm() function.
norm (const complex<T>& x); double norm (ArithmeticType x);Parameters
It returns the norm value of the complex number x.
Exceptionsnone
Example 1In the following example, we are going to consider the basic usage of the norm() function.
#include <iostream> #include <complex> int main() { std::complex < double > a(1.1, 1.3); double x = std::norm(a); std::cout << "Result : " << x << std::endl; return 0; }Output
Output of the above code is as follows −
Result : 2.9Example 2
Consider the following example, where we are going to use the norm() with the negative values.
#include <iostream> #include <complex> int main() { std::complex < double > x(-2.1, -3.2); double y = std::norm(x); std::cout << "Result : " << y << std::endl; return 0; }Output
Following is the output of the above code −
Result : 14.65Example 3
In the following example, we are going to use the norm() on the real part.
#include <iostream> #include <complex> int main() { std::complex < double > a(2.3, 0.0); double b = std::norm(a); std::cout << "Result : " << b << std::endl; return 0; }Output
If we run the above code it will generate the following output −
Result : 5.29
complex.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4