# Complex numbers in Octave

In this lesson I'll show you how to write **complex numbers** in Octave using a practical example.

There are two ways to write a complex number in Octave.

You can use the function **complex(a,b)** where a is the real part and b is the imaginary part.

>> complex(3,4)

Alternatively, you can write the complex number in **algebraic form** using the imaginary unit i or j.

>> 3+4i

Let me give you a practical example.

Go to Octave and type the complex number **a=3-4i**. Then press enter.

>> a = 3+4i.

The software recognizes that it is a complex number in algebraic form.

The complex number 3+4i is assigned to the variable a.

**Note**. You can also write the symbol for the imaginary unit using the letter j (e.g. 3+4j). Octave recognizes the complex number. However, the software automatically transforms the imaginary unit using the letter i (e.g. 3+4i).

Now type another complex number **b=2+5i** and press enter.

>> b = 2+5i

At this point there are two complex variables in memory.

You can perform any mathematical operation with the two numbers (e.g. addition, subtraction, multiplication, division).

For example, you can **add the two complex numbers**

>> a+b

ans = 8 + 5i

You can **subtract** the complex numbers

>> a-b

ans = -2 - 1i

>> b-a

ans = 2 + 1i

You can **multiply** the complex numbers

>> a*b

ans = 9 + 19i

You can also calculate the square of a complex number

>> a^2

ans = 5 + 12i

If this Nigiara guide has helped you, keep following us.