# Preface

This is a tutorial made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in normal font. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

# General Solutions

Consider linear differential operator of order n:

$L \left[ x, \texttt{D} \right] = a_n \texttt{D}^n + a_{n-1} \texttt{D}^{n-1} + \cdots + a_1 \texttt{D} + a_0 ,$
where $$\texttt{D} = {\text d} / {\text d}x$$ is the derivative operator (with respect to independent variable x).

Theorem: If coefficients $$a_n (x), a_{n-1} (x), \ldots , a_0 (x)$$ are continuous functions on some interval |a,b| and $$a_n (x) \ne 0 ,$$ then the homogeneous linear differential equation $$L \left[ x, \texttt{D} \right] y =0 ,$$ which can be written as

$a_n \, y^{(n)} + a_{n-1} \, y^{(n-1)} + \cdots + a_1 \, y' + a_0 \, y=0 ,$
has n linearly independent solutions $$\left\{ y_1 (x), y_2 (x), \ldots , y_n (x) \right\}$$ that are continuous on the interval |a,b|. Then the general solution of the equation on the interval is
$y (x) = C_1 \, y_1 (x) + C_{2} \, y_2 (x) + \cdots + a_{n-1} \, y_{n-1} (x) + a_n \, y_n (x) ,$
where $$C_1 , C_2 , \ldots , C_n$$ are arbitrary constants. ■

Theorem: Let yp be any particular solution of the nonhomogeneous linear n-th order differential equation

$a_n \, y^{(n)} + a_{n-1} \, y^{(n-1)} + \cdots + a_1 \, y' + a_0 \, y= f(x) ,$
on an interval |a,b|, and let $$\left\{ y_1 (x), y_2 (x), \ldots , y_n (x) \right\}$$ be a fundamental set of solutions of the associated homogeneous differential equation $$L \left[ x, \texttt{D} \right] y =0$$ on |a,b|. Then the general solution of the nonhomogeneous equation $$L \left[ x, \texttt{D} \right] y = f(x)$$ on the interval is
$y (x) = y_p (x) + C_1 \, y_1 (x) + C_{2} \, y_2 (x) + \cdots + a_{n-1} \, y_{n-1} (x) + a_n \, y_n (x) ,$
where $$C_1 , C_2 , \ldots , C_n$$ are arbitrary constants. ■

As we see from the previous Theorem, the general solution of a nonhomogeneous linear equation consists of the sum of two functions:

$y (x) = y_p (x) + y_h (x) ,$
The linear combination $$y_h (x) = C_1 \, y_1 (x) + C_{2} \, y_2 (x) + \cdots + a_{n-1} \, y_{n-1} (x) + a_n \, y_n (x) ,$$ which is the general solution of the homogeneous equation $$L \left[ x, \texttt{D} \right] y = 0$$ is sometimes called the complementary function for nonhomogeneous equation. In other words, to solve a nonhomogeneous linear differential equation $$L \left[ x, \texttt{D} \right] y = f(x)$$ we first solve the associated homogeneous equation $$L \left[ x, \texttt{D} \right] y = 0$$ and then find any particular solution of the nonhomogeneous equation.

If all coefficients of the linear differential operator $$L \left[ \texttt{D} \right]$$ are constants, then the general solution of the corresponding homogeneous equation $$L \left[ x, \texttt{D} \right] y = 0$$ exist for all x on real axis. In this case, it is [possible to find the fundamental set of solutions explicitly. Following Leonhard Euler, we seek solutions to the homogeneous linear constant coefficient equation

$a_n \, y^{(n)} + a_{n-1} \, y^{(n-1)} + \cdots + a_1 \, y' + a_0 \, y= 0$
as exponential function $$y (x) = e^{\lambda\,x} ,$$ for some parameter λ. Substituting the exponential function into the homogeneous equation, we get
$a_n \, \lambda^n \, e^{\lambda\,x} + a_{n-1} \, \lambda^{n-1} \,e^{\lambda\,x} + \cdots + a_1 \, \lambda \, e^{\lambda\,x} + a_0 \, e^{\lambda\,x} = 0 .$
Upon removing the common multiple $$e^{\lambda\,x} \ne 0,$$ we obtain a polynomial equation
$a_n \, \lambda^n + a_{n-1} \, \lambda^{n-1} + \cdots + a_1 \, \lambda + a_0 = 0 .$
The polynomial of degree n, denoted by $$L(\lambda ) ,$$ is called the characteristic polynomial corresponding to the linear constant coefficient differential operator $$L \left[ \texttt{D} \right] = a_n \texttt{D}^n + \cdots + a_1 \texttt{D} + a_0 .$$ If the characteristic equation $$L(\lambda ) =0$$ has n distinct roots (real or complex), we get n linearly independent exponential solutions that constitute the fundamental set of solutions for the given homogeneous linear constant coefficient differential equation.

A particular interest is a second order differential equation. Let us consider the equation of motion for undriven damped harmonic oscillator (coefficients μ and ω0 > 0 are assumed constants)

$\ddot{y} + 2\mu\,\dot{y} + \omega_0^2 y =0 ,$
subject to the initial conditions
$y(0) = y_0 , \qquad \dot{y}(0) = v_0 .$
Assuming that the roots of the characteristic equation $$\lambda^2 + 2\mu\,\lambda + \omega_0^2 =0$$ are distinct,
$\lambda_1 , \ \lambda_2 = - \mu \pm \eta = -\mu \pm \left( \mu^2 - \omega_0^2 \right)^{1/2} , \qquad \eta = \left( \mu^2 - \omega_0^2 \right)^{1/2}$
the differential equation has two linearly independent solutions $$y_{1,2} = e^{\lambda_{1,2} t} .$$ Then the solution (which is unique) of the given initial value problem can be expressed as
\begin{align*} y(t) &= \frac{y_0 \lambda_2 - v_0}{\lambda_2 - \lambda_1}\, e^{\lambda_1 t} - \frac{y_0 \lambda_1 - v_0}{\lambda_2 - \lambda_1}\, e^{\lambda_2 t} . \end{align*}

Example: We consider the second order linear differential operator:

$L \left[ x, \texttt{D} \right] = \texttt{D}^2 - \texttt{D} -6 .$
The corresponding characteristic polynomial $$L(\lambda ) = \lambda^2 - \lambda -6 = (\lambda +2)(\lambda -3)$$ has two distinct real roots $$\lambda =-2$$ and $$\lambda = 3 .$$ Then the functions $$y_1 (x) = e^{-2x}$$ and $$y_2 (x) = e^{3x}$$ form a fundamental set of solutions, and the general solution to $$L \left[ x, \texttt{D} \right] y = 0$$ is
$y(x) = C_1 e^{-2x} + C_2 e^{3x} ,$
where C1 and C1 are arbitrary constants.
roots = Solve[s^2 - s - 6 == 0, s]
first = s /. roots[[1]]
second = s /. roots[[2]]
root = {first, second}
Soln = Map[Exp[# x] &, root]
{E^(-2 x), E^(3 x)}
AllSoln[x_]=Soln.{c1,c2}
Out[17]= c1 E^(-2 x) + c2 E^(3 x)
Simplify[L[x, AllSoln] == 0] (* check the answer *)
Out[18]= True
DSolve[y''[x] - y'[x] - 6 y[x] == 0, y[x], x]

Example: We consider the third order linear differential operator:

$L \left[ x, \texttt{D} \right] = \texttt{D}^3 - 2\,\texttt{D}^2 - 5\,\texttt{D} +6 .$
The corresponding characteristic polynomial $$L(\lambda ) = \lambda^3 -2\,\lambda^2 - 5\,\lambda +6 = (\lambda -1)(\lambda +2)(\lambda -3)$$ has three distinct real roots $$\lambda =1,$$ $$\lambda =-2 ,$$ and $$\lambda = 3 .$$ Then the functions $$y_1 (x) = e^{x} , \quad y_1 (x) = e^{-2x} ,$$ and $$y_3 (x) = e^{3x}$$ form a fundamental set of solutions, and the general solution to $$L \left[ x, \texttt{D} \right] y = 0$$ is
$y(x) = C_1 e^{x} + C_2 e^{-2x} + C_3 e^{3x} ,$
Now we use Mathematica to show that these functions indeed form a fundamental set of solutions.
L[x_, y_] = y'''[x] - 2 y''[x] - 5 y'[x] + 6 y[x]
char[lambda_] =Coefficient[L[x,Function[t,Exp[lambda t]]],Exp[lambda x]]
roots = r /. Solve[char[r] == 0, r]
solns = Map[Function[k, Exp[k x]], roots]
y[x_] = solns.{c2,c1,c3} (
Clear[x, y];
L[x_,y_] =y''[x] -y'[x]- 6y[x]
CharPoly[lambda_] =Coefficient[L[x,Exp[lambda #]&], Exp[lambda x]]
roots =lambda/.Solve[CharPoly[lambda]==0,lambda]
* or *)
Clear[x,y];
L[x_, y_] = y'''[x] - 2 y''[x] - 5 y'[x] + 6 y[x]
DSolve[L[x, y] == 0, y[x], x]
y[x_] = Expand[y[x] /. %[[1]] ]
basis = Table[Coefficient[y[x], C[i]], {i, 1, 3}]
Factor[Coefficient[L[x, Function[t, Exp[r t]]], Exp[r x]]]
W[x_] = NestList[Function[t, D[t, x]], basis, 2]
Det[W[x]]
Out[7]= 30 E^(2 x) (* Wronskian *)