The C++ std::complex::conj() function is used to return the complex conjugate of a given complex number. The complex number consists of real and imaginary part, and its conjugate is obtained by chnging the sign of the imaginary part. For example, the conjugate of the complex number x+yi, is x-yi.
SyntaxFollowing is the syntax for std::complex::conj() function.
conj (const complex<T>& x); complex<double> conj (ArithmeticType x);Parameters
It returns the conjugate of the complex number x.
Exceptionsnone
Example 1In the following example, we are going to consider the basic usage of the conj() function.
#include <iostream> #include <complex> int main() { std::complex < double > x(1.1, 1.3); std::complex < double > x1 = std::conj(x); std::cout << "Original: " << x << std::endl; std::cout << "Conj: " << x1 << std::endl; return 0; }Output
Output of the above code is as follows −
Original: (1.1,1.3) Conj: (1.1,-1.3)Example 2
Consider the following example, where we are going to use the conj() with the zero imaginary part.
#include <iostream> #include <complex> int main() { std::complex < double > x(1.2, 0.0); std::complex < double > x1 = std::conj(x); std::cout << "Original: " << x << std::endl; std::cout << "Conj: " << x1 << std::endl; return 0; }Output
Following is the output of the above code −
Original: (1.2,0) Conj: (1.2,-0)Example 3
Let's look at the following example, where we are going to use the conj() with the negative values.
#include <iostream> #include <complex> int main() { std::complex < double > x(-1.2, -2.2); std::complex < double > x1 = std::conj(x); std::cout << "Original: " << x << std::endl; std::cout << "Conj: " << x1 << std::endl; return 0; }Output
If we run the above code it will generate the following output −
Original: (-1.2,-2.2) Conj: (-1.2,2.2)
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