lettura simple

How to extract the real and imaginary part of a complex number in Octave

In this lesson, I'll show you how to extract the real and imaginary part of a complex number in Octave using a practical example.

What are the real and imaginary parts of a complex number? A complex number is always presented in the form z = a + b⋅i $$ z = a+b \cdot i $$ where i is the imaginary unit and a, b are real numbers. The real part of the complex number is the real number "a". The imaginary part of the complex number is the number "b" multiplied by the imaginary unit "i".

First, define a complex number.

For example z=2+3i

>> z=2+3i

To extract the real part of the complex number, use the function real()

In this case, the real part of the complex number z=2+3i is equal to 2.

>> real(z)
ans = 2

To extract the imaginary part of the complex number, instead, use the function imag()

The imaginary part of the complex number z=2+3i is the real number 3.

>> imag(z)
ans = 3

If you like this Nigiara lesson, keep following us.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin