IMSE Chapter 7

IMSE-07(Complex).nb
Complex Numbers and Variables
RCH 8/20/01
revised 6/24/02 - rjerwin

This notebook explores the use of complex numbers and complex variables in Mathematica.

Mathematica allows you to use complex numbers and complex variables in a fairly straightforward fashion.  In fact, for the most part, you don't need to do anything specific to use a complex number or a complex variable.  Activate the following cell.

(Sqrt[-5])

You see that Mathematica uses i = (Sqrt[-1])to signify a complex number (in this case, a purely imaginary complex number).  The symbol i is available on the BasicInput palette.  Alternatively, you can use the letter I, but be sure to separate it by a space from the number or variable that follows.  The following cells illustrate the manipulation of complex variables.

Clear[a, b, c, d, g, k, r, s]

c = a + I b;
d = r + I s;
c + d 
c*d

a = 5;
b = 3;
r = 1;
s = -4;
c + d
c*d

The next cell illustrates what happens if you fail to leave a space between i (or I) and the following number or symbol.

g = 5 + Ia
c*g

Mathematica thinks that you have defined a new variable ia.

Lesson:  Keep a space after i or use i*a.

g = 5 + I*a
c*g

Real and Imaginary Parts and Absolute Values

To find the real and imaginary parts of a complex number, you use Re[] and Im[] as illustrated in the following cell.  In each case, verify that Mathematica gives the expected result.

Re[c*g]
Im[c + g]

Abs[c*g]
Abs[c + g]

In  Mathematica, taking the complex conjugate is done with the Conjugate[] function.

c
Conjugate[c]

Mathmatica also knows functions of a complex variable.

Sin[I*k]

Re[(E^(I θ))]

Note that in evaluating the previous expression Mathematica assumed that θ itself is a complex variable.

For the most part, you can use complex numbers and variables freely in computations, differential equations, integrals, etc.  Not surprisingly, you can't plot a complex-valued function.

Plot[(Sqrt[1 - x^2]), {x, 0, 2}];

As you work with complex number calculations in Mathematica you may occasionally find numbers with very small imaginary parts.  For example, taking the Fourier transform of a list of real numbers produces a list of complex numbers.

ft = Table[Random[Real, {0, 5}], {10}]

fft = Fourier[ft]

We can get rid of the small imaginary part by using Chop.

Chop[fft]