Complex Numbers/Complex Plane

Background

The positive square root of -1

imaginary  = Sqrt[-1]

(-imaginary)^2

Complex numbers are composed of a real part + an imaginary part

z1  =  a  +  I b;
z2 =  c  +  I d;

Simple operations on complex numbers

compadd  =  z1  +  z2;

compmult  =  z1*z2;

Simplify[compmult, 
      a ∈  Reals  &&  b ∈  Reals  && 
        c  ∈  Reals  &&  d  ∈  Reals ]

Mathematica does not assume that symbols are necessarily real...

Re[compadd]
Im[compadd]

However, the Mathematica function ComplexExpand does assume that the variables are real....

ComplexExpand[Re[compadd]]

ComplexExpand[Im[compadd]]

ComplexExpand[Re[z1/z2]]

ComplexExpand[compmult]

ComplexExpand[Re[z1^3]]
ComplexExpand[Im[z1^3]]

Function to convert to Polar Form

Pform[z_]  :=  Abs[z] Exp[I Arg[z]]

Note: the function Arg[z] returns an angle in the range -π to π which measures the inclination of z with respect to the +Re axis in the complex plane.

Pform[z1]

Pform[z1 /. {a -> 2, b -> -π}]

ComplexExpand[Pform[z1]]

Numerical Precision and Complex Rounding

ExactlyOne  =  Exp[2 π I]

NumericallyOne  = Exp[N[2 π I]]

Chop[NumericallyOne]

Round[NumericallyOne]

ExactlyI  =  Exp[π I/2]

NumericallyI  =  Exp[N[π I/2]]

Round[NumericallyI]

Chop[NumericallyI]

ExactlyOnePlusI  =  
      ComplexExpand[(Sqrt[2]) Exp[π  I/4]]

NumericallyOnePlusI  =  
      ComplexExpand[(Sqrt[2]) Exp[N[π  I/4]]]

Chop[NumericallyOnePlusI]

Round[NumericallyOnePlusI]

Re[NumericallyOnePlusI]

Im[NumericallyOnePlusI]

Roots to Polynomial Equations

Complex numbers frequently appear in the solution of roots to polynomial equations:

sols  =  
      Solve[(x^4  - x^3  + x  + 1)  ==  0, x]

The next statement produces a list of the complex solutions of the polynomial:

x /. sols

Im[x /. sols]

ComplexExpand[Im[x /. sols]]

ComplexExpand[Im[x /. sols]] // N

ComplexExpand[Re[x /. sols]] // N

Generalize the above to a family of solutions: find b such that imaginary part of the solution vanishes

bsols  =  
      Solve[(x^4  - x^3  + b*x  + 1)  ==  0, x]

This will give a list of rules that can be used to find solutions;as "b" is unspecified the rules depend on the symbol "b"

Because it is a long set of rules and hard to follow, let's look at the form of bsols:

Dimensions[bsols]

Short produces a very abbreviated form of the solution… in this case limited to 3 lines by the optional parameter.

Short[bsols, 3]

So we see that bsols is a list of length 4 of list containing one rule. (Solutions to equations are always this way, it is a list of the number of solutions, each member being a rule for each variable that is solved for...)

In our case of one variable, the extra layer of lists is not terribly useful, one way to get rid of the extra layers is to use Flatten:

Dimensions[Flatten[bsols]]
Short[Flatten[bsols], 3]

In the next command, we produce a list of values (not of rules, because we have taken x and applied every rule in bsols to it... These values are the imaginary parts of the solutions x that make the polynomial vanish (and a function of b, because it hasn't been specified yet)

imb  = ComplexExpand[Im[x /. bsols]];

Dimensions[imb]
Short[imb[[1]]]

And likewise for the real parts of x that solve the polynomial equation

imr = ComplexExpand[Re[x /. bsols]];

Plot[] expects a list of functions to plot, The "Flatten" function ensures that Plot is getting a list, but it is redundant in this particular case.  This plot works as follows, for each member in the list, plot the result of replacing b with q for values of q between -10, 10---it is a long-handed way of seeing exactly what is going on and demonstrates the replacement technique.

So the following should be  a plot of the imaginary values of x as a function of b.

Plot[
      Evaluate[Flatten[imb] /. b -> q], {q, -10, 10}]

In fact, we should be able to do the  same thing without replacement as the following shows, it is probably instructive to show both ways.

Plot[Evaluate[imb], {b, -10, 10}]

There are a few problems that make it difficult to interpret the graph---one is the numerical noise that makes the solutions
jump back and forth; second, because all the colors are the same,  it is not clear which values of x belong to the same solution.  

Let's first try to make each member of the list (remember, there are 4 because it is a fourth-order polynomial and because Dimensions[imb] told us so...

Plot[Evaluate[Flatten[imb] /. b -> q], {q, -10, 10}, 
      PlotStyle -> Table[{Hue[1 - a/6]}, {a, 1, 4}]]

The plot above is a little better, it looks like the blue curve comes in from the northeast and then then its imaginary part vanishes at a critical values of q (around -0.5), the cyan curve is probably the minus values of the blue curve... and the same thing for yellow and green.  It is much easier to see the branches of solutions for the real parts below.

Plot[Evaluate[Flatten[imr] /. b -> q], {q, -10, 10}, 
      PlotStyle -> Table[{Hue[1 - a/6]}, {a, 1, 4}]]

But here, because the lines are the same thickness, we don't know if the cyan and blue curves just "stop." Let's find out by also adjusting their thickness.

Plot[Evaluate[Flatten[imr] /. b -> q], {q, -10, 10}, 
      PlotStyle -> 
        Table[{Hue[1 - a/6], Thickness[0.05 -  .01*a]}, {a, 1, 
            4}]]

It is pretty clear that the parameter b is behaving like a "pitchfork" bifurcation---there is one value of x upto a critical value of b, where x splits into two solutions.  This is a picture of two isolated pictchforks.