Lab 7 pre-lab: Complex arithmetic

In this week's lab, we'll be using classes to create our own types. To keep the conceptual part of it simple, we'll use the well-defined idea of arithmetic on complex numbers as our first example. This reading provides a review of how complex numbers work.

A complex number is expressed as the sum of its real part and its imaginary part, as in

3.2 + 4.3i
The i stands for the square root of -1. (You might recall that numbers like that are called imaginary because the square root of a negative number does not make much sense in the physical world.)

For this lab, you don't need to understand all of the details of imaginary numbers, but you do need to be able to do basic arithmetic, for which the it my be helpful to think in which the variable is i. So for addition or subtraction, you just need to add or subtract the corresponding terms:

a + bi   +   c + di    = (a+c) + (b+d)i

Multiplication is not much more complicated:

(a + bi) * (c + di)
gives you
(a*c) + (a*d)i + (b*c)i + (b*d)i2
Simplifying, and recognizing the i2 is -1, we get
(a*c - b*d) + (b*c + a*d)i

Division is trickier, because we need to get the quotient for

(a + bi) / (c + di)
into the form
x + yi
So we have to somehow make the i terms in the denominator vanish. We can do that by making use of what is known as the complex conjugate: for c + di,
conj(c + di) = c - di
The useful fact is that the i terms vanish when we mulitply by the conjugate:
(c+di) * conj(c+di)
    = (c + di) * (c - di)
    = c*c + c*-di) + di*c + (d*-d)i2
    = c2 + (-c*d + c*d)i + -(-d2)
    = c2 + d2
Taking advantage of this, and multiplying both numerator and denominator of
(a + bi) / (c + di)
by conj(c+di), we get
((a+bi)*conj(c+di))
   / ((c+di) * conj(c+di))
But our denominator is now the real number c2+d2, by which we can divide each term of the product in the numerator.

Try working that out for the following examples:

(4+0i) / (2+0i)
(4+0i) / (0+2i)
(4+4i) / (1+1i)
(8+4i) / (1-1i)
I, read the pre-lab

Cary Gray
Last modified: Fri Jan 30 07:46:15 CST 2015