
Complex Number Operations with Octave
In this lesson, I will explain how to perform the main mathematical operations with complex numbers on Octave through some practical examples.
To begin, define two complex numbers and assign them to the variables z1 and z2.
>> z1=2+3i
z1 = 2 + 3i
>> z2=4+5i
z2 = 4 + 5i
To add complex numbers, you simply use the same plus (+) operator as you would for real numbers.
>> z1+z2
ans = 6 + 8i
To perform the subtraction of complex numbers, use the minus (-) operator.
>> z1-z2
ans = -2 - 2i
To calculate the multiplication between complex numbers, use the asterisk (*) operator.
>> z1*z2
ans = -7 + 22i
If you want to calculate the division between complex numbers, use the symbol of the forward slash (/).
>> z1/z2
ans = 0.560976 + 0.048780i
To raise a complex number to a power, use the caret symbol "^".
>> z1^2
ans = -5 + 12i
To calculate the square root of a complex number, use the sqrt() function.
>> sqrt(z1)
ans = 1.67415 + 0.89598i
Finally, to calculate the nth root of a complex number, raise the number to the inverse of n.
By using this method, you can find all the nth roots of a complex number
>> z1^1/3
ans = 0.66667 + 1.00000i
Note. When dealing with the nth root, the nthroot() function is not applicable as it only allows for real values.
If you find this Nigiara lesson interesting, we invite you to keep following us.