Javatpoint Logo
Javatpoint Logo

conj() function in C++

The conj() function in C++ is present in the standard library. C++ provides a wide range of inbuilt functions for complex numbers. It is also a built-in function that deals with complex numbers. This function is provided by the <comple> header file. The main intention of this function is to return the conjugate of the complex number when we give a complex number to it. In this article, we will learn about the syntax of the conj() function, programs related to this function and an explanation of the function.

Example:

conjugate of complex number (a + b*i) is (a-b*i)

where a and b are the real numbers

Syntax of the conj() function:

It has the following syntax:

Here, "T" represents the data types of the real and imaginary parts of the complex numbers. This function takes the complex number "x" as argument, and it returns the complex conjugate of the complex number "x".

Example:

Let us take a C++ program to illustrate the conj() function:

Output:

conj() function in C++

Explanation:

In this example, we include the <complex> header file in the program. Two variables, real_part and imaginary_part, are declared and given the values taken from the user input. Here, complexNumber<> will represent the complex number with a real part and an imaginary part, and it creates the complex object. After that, this complex number will be given to the conj() function so that it returns the conjugate of the complex number, and then the complex and its conjugate will also printed.

Example 2:

Let us take an example to find the magnitude of the complex number using the conj() function in C++:

Output:

conj() function in C++

Explanation:

In this example, a static complex number is taken, and its magnitude is calculated and then printed in the console. In this program, we also included headers like <complex> and <cmath> for finding the magnitude.

Example:

Let us take a C++ program to illustrate the conj() function and its usage:

Output:

conj() function in C++

Explanation:

In this example, AC circuit power of 120 + 80i volts amps is a complex number. Its real part represents the actual power consumed by the circuit, and the imaginary part represents the reactive power.

We first calculate the complex conjugate of the complex number by using the inbuilt function conj(). After that, we calculate the magnitude of the complex number, which is equivalent to the apparent power consumed by the circuit.

The real part of the complex power represents the actual power consumed in watts.

The imaginary part of the complex power represents the reactive power consumed in VAR (volt-amperes reactive).

This example demonstrates how complex numbers and the std::conj() function can be used to solve real-world problems in electrical engineering, helping engineers analyze and optimize AC circuits.

Conclusion:

The conj() function in C++ provides a convenient way to calculate the complex conjugate of a complex number. Its simplicity and efficiency make it a valuable tool for working with complex numbers in various applications, ranging from mathematics and physics to engineering and signal processing. By understanding the syntax and usage of the conj() function, programmers can enhance their ability to manipulate complex numbers effectively, opening doors to a wide array of computational possibilities.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA