logo
Home Articles Tutorials BLAH! Links


Complex Math…

…is not difficult. Let me explain the basics.

We’re all used to real numbers. Examples of these are 1, 2, 3/5 and pi. Nothing out of the ordinary there..

Complex numbers

There is another class of numbers, called complex numbers. Complex numbers have a real part and an imaginary part. An example of a complex number is 1 + i3, where ‘1’ is the real part and ‘3’ is the imaginary part. The ‘i’ in front of the number signifies that the ‘3’ is imaginary.

In a general form, a complex number c is written as:

,where α is the real part and β is the imaginary part.

The ‘i’ has special properties. It turns out that if you multiply ‘i’ with ‘i’ you get -1:

That is actually the definition of ‘i’! Some books will define ‘i’ as

Whatever your preferred definition, you must remember to keep the imaginary part separate from the real part. The parts are independent. You can even view a complex number as a 2-dimensional vector or (x,y) coordinates.

Adding and subtracting complex numbers

Adding and subtracting complex numbers is very simple. You add or subtract the real and imaginary parts separately, like this:

Or in general form:

Multiplying complex numbers

Multiplying complex numbers is slightly more .. ehh.. complex. We must write out the multiplication:

We can add the two imaginary parts together, like this:

But wait! Didn’t we see that ‘i’ times ‘i’ is -1? We can simplify some more:

So (3+i2) (4+i5) = 12 - 10 + i(15 + 8) = 2 + i23!

And (2+i1) (2-i3) = 4 + 3 + i(2 – 3) = 7 - i1! (watch those minus signs!)

Absolute value and complex conjugate

The complex conjugate of a complex number is the same number but with a reversed sign of the imaginary part:

The absolute value of a complex number is defined as:

Let’s write that one out…

Hey.. We know that formula! It’s Pythagoras’ theorem! Note that the absolute value of a complex number is a real number. Because α and β are squared, the result will always be positive.

Exponents

There is one very important function in signal processing that will come back time and again. It’s the imaginary exponent of the natural base ‘e’ and is defined as:

We will encounter this function in the analysis of filters so it is important to know this identity.

Okay, now where is the fun in this?

You now have enough knowledge to plot the Mandelbrot set, shown below:

Plot the Mandelbrot set using this pseudo-code:

for(int y=0; y<480; y++)
{
for(int x=0; x<800; x++)
{
complex c = 3*(x/800)-1 + i( (3*y/480) - 1.5);
complex z = c;
int iter = 0;
while((|z|<2) && (iter < 256))
{
z = z*z + c;
iter++;
}
Pixel(x,y, iter); // plot pixel at (x,y) with color ‘iter’
}
}

You can optimize |z|<2 by realizing that it is the same as z*conj(z) < 4, which saves you a square root!

EOF

I hope you enjoyed this small tutorial. Complex math is very important in a lot of fields such as signal processing. As we will later see, complex math can make life a lot easier. You need to know this stuff or you’ll be left behind...

shadowHugger.






This site was made using Webhare Lite.