Demo #5
Complex Numbers and Constant Coefficient ODE's

In this demo, we will see how Mathematica can help out when solving higher order linear, homogeneous equations with constant coefficients. 

To begin, let's review what Demo #1 tells us about  how Mathematica represents complex numbers and the built-in functions that are available for doing complex algebra manipulations:

Complex Numbers

As mentioned in the previous section, complex numbers may be denoted by adding the constant I.

?I

Sqrt[-4]

N[Exp[2 + 9 I]]

This is how we add two complex numbers:

(6 +  4 I )  +  (5  +  8 I )

We can also multiply or divide complex numbers:

(4  +  5.5 I ) * (3  -  2 I )

Useful Commands for Complex Numbers:

Re[z]  ->  real part of z
Im[z]  ->  imaginary part of z
Conjugate[z]  ->  complex conjugate of z
Abs[z]  ->  absolute value (magnitude) of z
Arg[z]  ->  argument (phase) of z

Examples:

N[Re[Exp[2 + 9 I]]]

N[Im[Exp[2 + 9 I]]]

N[Conjugate[Exp[2 + 9 I]]]

N[Abs[Exp[2 + 9 I]]]

N[Arg[Exp[2 + 9 I]]]

Now, let's return to the task of solving ODE's with constant coefficients. To be specific, let's consider a particular homogeneous ODE:

diffeq = y'''[x] - 3 y''[x] + y[x] == 0

Now, if we assume exponential solutions of the form y = Exp[ r x], the following characteristic equation is obtained:

chareq = r^3 - 3 r^2 + 1 == 0

This is a cubic polynomial equation in the parameter r. Suppose we just try to "solve" this polynomial equation using Mathematica's polynomial solver:

soln1 = Solve[ chareq, r]

This mess is indeed the three roots of the cubic equation, and although they appear to be complex roots ("I" is Sqrt[ -1]), they are actually real when all the complex arithmetic is worked out.

A simple plot confirms three real roots:

Plot[ r^3 - 3 r^2 + 1,{r,-1,3}]

Numerical values for the roots are obtained by:

NSolve[ chareq,r]

The analytical solution is thus a linear combination of three exponentials with these values of r. A simple way to quickly generate this in Mathematica is:

DSolve[ diffeq, y[x],x] //N

where we recognize e = 2.71828... Notice that the "//N" is needed to prevent Mathematica from using the complicated exact expressions for the roots of the characteristic equation instead of more transparent numerical values.

In summary, tools like Mathematica can be extremely useful, even when analytical solutions to ODE's are possible, as in the present case of linear, homogeneous equations with constant coefficients.