Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

### Complex Number Manipulation

Let's run through a few elementary manipulations of complex numbers in Matlab:

```>> x = 1;
>> y = 2;
>> z = x + j * y

z =
1 + 2i

>> 1/z

ans =
0.2 - 0.4i

>> z^2

ans =
-3 + 4i

>> conj(z)

ans =
1 - 2i

>> z*conj(z)

ans =
5

>> abs(z)^2

ans =
5

>> norm(z)^2

ans =
5

>> angle(z)

ans =
1.1071
```

Now let's do polar form:

```>> r = abs(z)

r =
2.2361

>> theta = angle(z)

theta =
1.1071
```

Curiously, is not defined by default in Matlab (though it is in Octave). It can easily be computed in Matlab as `e=exp(1)`.

Below are some examples involving imaginary exponentials:

```>> r * exp(j * theta)

ans =
1 + 2i

>> z

z =
1 + 2i

>> z/abs(z)

ans =
0.4472 + 0.8944i

>> exp(j*theta)

ans =
0.4472 + 0.8944i

>> z/conj(z)

ans =
-0.6 + 0.8i

>> exp(2*j*theta)

ans =
-0.6 + 0.8i

>> imag(log(z/abs(z)))

ans =
1.1071

>> theta

theta =
1.1071

>>
```
Here are some manipulations involving two complex numbers:
```>> x1 = 1;
>> x2 = 2;
>> y1 = 3;
>> y2 = 4;
>> z1 = x1 + j * y1;
>> z2 = x2 + j * y2;
>> z1

z1 =
1 + 3i

>> z2

z2 =
2 + 4i

>> z1*z2

ans =
-10 +10i

>> z1/z2

ans =
0.7 + 0.1i
```

Another thing to note about matlab syntax is that the transpose operator ' (for vectors and matrices) conjugates as well as transposes. Use .' to transpose without conjugation:

```>>x = [1:4]*j

x =
0 + 1i   0 + 2i   0 + 3i   0 + 4i

>> x'

ans =
0 - 1i
0 - 2i
0 - 3i
0 - 4i

>> x.'

ans =
0 + 1i
0 + 2i
0 + 3i
0 + 4i
```

Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]