# Topic 4 Linear Second Order Differential Equations

## 4.1 The general solution of a linear equation

Consider the linear second order differential equation \[y''+p(x)y'+q(x)y=f(x).\] Let \(y_p\) be a particular solution, and \(y_h\) the general solution of the associated homogeneous equation \[y''+p(x)y'+q(x)y=0.\] Then the function \(y_h+y_p\) is the general solution of the non-homogeneous equation \(y''+p(x)y'+q(x)y=f(x)\).

The function \(y_h\) can be written as \(c_1y_1+c_2y_2\), where \(y_1\) and \(y_2\) are linearly independent solutions of the associated homogeneous equation. To find \(y_1\) and \(y_2\), we can use `dsolve`

with the option `output=basis`

.

**Example 4.1 **Find two linearly independent solutions of the equation
\[y''+ y=0.\]

*Solution*. We first run commands which provide better display.

```
PDETools[declare](y(x), prime=x): # Turn ON the enhanced DEdisplay feature
infolevel[dsolve] := 3: # Show more detailed information about computation
```

Now define the equation

`ode31:=diff(y(x), x$2)+y(x)=0 # here x$n = x, x, ..., x, n copies of x`

To find the independent solutions, run the following command

`dsolve(ode31, y(x), output=basis)`

The output is \[ \color{blue}{[\sin(x), \cos(x)]} \] which means that \(\sin x\) and \(\cos x\) are linearly independent solutions.

If the homogeneous linear equation has constant coefficients, then one can also use
`DETools[constcoeffsols]`

to find a list of independent solutions.

**Exercise 4.1 **Find two linearly independent solutions of the equation
\[y'' - y' - 2y=0.\]

To find a particular solution of a nonlinear ODE, or a linear non-homogeneous ODE, one can use the command `particularsol(ODE, dependent variable)`

.

**Example 4.2 **Find a particular solution to the equation
\[y''-3y'+2y=2.\]

*Solution*. First define the equation

`ode32:=diff(y(x), x, x)-3*diff(y(x), x)+2*y(x)=2`

To find a particular solution, we can use

```
with(DETools):
particularsol(ode32, y(x));
```

or

`DETools[particularsol](ode32, y(x))`

**Exercise 4.2 **Find a particular solution to the equation
\[y''-3y'+2xy=2x^2-3.\]

## 4.2 Wronskian of Solutions

The Wronskian of two solutions \(y_1\) and \(y_2\) of a linear homogeneous second order differential equation \(y''+p(x)y'+q(x)y=0\) is defined by
\[W(y_1, y_2)=y_1y_2'-y_1'y_2\]. In Maple, one can use the command `Wronskian([y_1, y_2], independent variable, determinant=true)`

or `LinearAlgebra[Determinant](Wronskian([y_1, y_2], independent variable)`

to find the Wronskian.

**Example 4.3 **The equation \(x^2y''+ 3xy'-3y=0\) has two solutions \(y_1=x\) and \(y_2=x^{-3}\). Find the Wronskian and determine if the two solutions are linearly independent.

*Solution*. We first load the package `VectorCalculus`

.

`with(VectorCalculus):`

Now we calculate the Wronskian.

`LinearAlgebra[Determinant](Wronskian([x, x^(-3)], x))`

The output is \[\color{blue}{-\frac{4}{x^{3}}}.\]

Because the Wronskian is not identically zero, the solutions are linearly independent.

**Exercise 4.3 **The equation \(x^2y''+ 4xy'-4y=0\) has two solutions \(y_1=x\) and \(y_2=x^{-4}\). Find the Wronskian and determine if the two solutions are linearly independent.

## 4.3 Linear Equations with Constant Coefficients

When solving linear equations with constant coefficients, we need to solve equations and system of equations. That can be done by the Maple command `solve({equations}, {unknowns})`

. Moreover, one can add constrains by using `assuming`

together with `solve`

.

**Example 4.4 **Solve the initial value problem
\[y''-2y'-3y=0,\qquad y(0)=1, y'(0)=-1.\]

*Solution*. Since this equation is a linear second order equation with constant coefficient, the solution is determined by the roots of the characteristic equation \(r^2-2r-3=0\). Running the following Maple command will give us the roots.

`rts:=solve(r^2-2*r-3=0, r);`

The roots are \[\color{blue}{3, -1}.\]

Since the root are real numbers, the general solution of the differential equation is

`yh(x):=c1*exp(rts[1]*x)+c2*exp(rts[2]*x);`

The initial conditions impose two equations for the constants `c1`

and `c2`

. We can calculate \(y'\) using `D(y)`

and solve the constants by the following command

`consts:=solve({yh(0)=1, D(yh)(0)=-1}, {c1,c2});`

The output is \[\color{blue}{\{{c1} = 0, {c2} = 1\}}.\]

So the solution to the initial value problem is \[y(x)=e^{-x}\] which can be seen by the maple commands

```
y(x):=subs(consts, yh(x));
y(x);
```

Here, we take the approach of solving the problem manually. In Maple, we can use `dsolve`

or `constcoeffsols`

to solve differential equations with constant coefficients.

**Exercise 4.4 **Solve the initial value problem
\[y''+3y'+2y=0,\qquad y(0)=3, y'(0)=1.\]

## 4.4 Undetermined Coefficients

For some equations that can be written into the form \[ay''+by'+cy=f(x)\], a particular solution can be found using the method of undetermined coefficients. Calculations can be made easy using Maple.

**Example 4.5 **Find a particular solution of
\[y''-5y'+6y=3e^{2x}.\]

*Solution*. Since the right hand side is an exponential function, and 2 is a root of the characteristic polynomial of the complementary equation, we expect a specific solution \(y_p=Axe^{2x}\). We then plug it into the equation to solve for \(A\).

Define the differential equation and the solution function.

```
ode341:=diff(y(x), x, x)-5*diff(y(x), x)+6*y(x)=3*exp(2*x);
yp(x):=A*x*exp(2*x);
```

Plugging \(y_p\) into the differential equation and solve for A. Since \(A\) is a number such that the equation is true for any \(x\). We use the `solve/identity`

method. The command runs like `solve(identity(equation, x), vars)`

.

```
eqnA:=subs[eval](y(x)=yp(x), ode341);
A=solve(identity(eqnA, x), A);
```

The output is \[\color{blue}{A = -3}.\]

Instead of using the `solve/identity`

scheme, one can also build systems of equations for the undetermined coefficients manually.

When \(f(x)\) involves a polynomial, we want to get a system of undetermined coefficients. One way is to substitute \(x\) by some general numbers. Another way is to differentiate both sides and then plug in \(x=0\). Once we get a system of the unknowns, we can solve it by the Maple command `solve({eq1, eq2, ...}, {unknown1, unknown2, ...})`

.

When \(f(x)\) involves sine or cosine, surely, we can plug in some general values for \(x\) to obtain a system. We may also substitute \(\sin x\) by \(0\) and \(\cos x=0\) to get two equations. From those two equations, we can build a system.

**Example 4.6 **Find a particular solution of
\[y''- 2y'-3y=x\sin x.\]

*Solution*. We expect a specific solution of the same type as the right hand side. Let’s try \(y_p=(ax+b)\cos x+(cx+d)\sin x\). We then plug it into the equation to solve for \(a\), \(b\), \(c\), and \(d\).

Define the differential equation and the solution function.

```
ode342:=diff(y(x), x, x)-2*diff(y(x), x)-3*y(x)=x*sin(x);
yp(x):=(a*x+b)*cos(x)+(c*x+d)*sin(x);
```

Plugging \(y_p\) into the differential equation and solve for A.

`eqnB:=subs[eval](y(x)=yp(x), ode342);`

Now let’s deduce a system of equations for \(a\), \(b\), \(c\) and \(d\).

```
# get an equation from coefficients of cosine
CoefCosine := subs([sin(x) = 0, cos(x) = 1], eqnB);
# get an equation from coefficients of sine
CoefSine := subs([sin(x) = 1, cos(x) = 0], eqnB);
# Get four equations for a, b, c, and d
eq1 := subs(x = 0, CoefCosine):
eq2 := subs(x = 0, CoefSine):
eq3 := diff(CoefCosine, x):
eq4 := diff(CoefSine, x):
```

Now we solve the equations as a system.

`abcd:=solve({eq1, eq2, eq3, eq4},{a, b, c, d});`

The output is \[\color{blue}{\left\{a = \frac{1}{10}, b = -\frac{7}{50}, c = -\frac{1}{5}, d = -\frac{1}{50}\right\} }.\]

Let’s verify that the solution.

```
Sol:=subs(abcd, yp(x)) # plug a, b, c, d in yp(x)
odetest(Sol, ode342)
```

If \(f(x)\) is a polynomial, one can also use the command `polysol`

to find a polynomial solution.

**Exercise 4.5 **Find a particular solution of
\[y''- 5y'- 6y=2e^{3x}.\]

## 4.5 Reduction of Order

Given a solution \(y_1\) of a linear second order differential equation \(y'' + p(x)y' + q(x)y=f(x)\), one can use the trick of variation of parameter to find another solution in the form \(y_2=y_1v\), here \(v\) satisfies a second order equation in the form \(y_1v'' + v'(p(x)y_1+2y_1)=0\). This equation can be solve by reduction of order using the substitution \(u=v'\). Indeed, we can expect \(y_2=y_1\int u(x)\mathrm{d}x\).

In Maple, one can use the command `reduce_order(ode, y(x)=y_1(x), u(t))`

to obtain a lower order equation for \(u\). This command again belongs to the package `DETools`

.

**Example 4.7 **The equation \(x^2y''+ 4xy'-4y=0\) has a solution \(y_1=x\). Find another linearly independent solution \(y_2\).

*Solution*. Let’s load packages first. Since `with`

can only load one package each time, let’s use a `for`

loop to load packages. To make the display looks better, let’s also run the `declare`

command.

```
for i in [DETools, LinearAlgebra, PDETools] do with(i) end do:
declare(y(x), prime=x):
```

Define the equation

`ode35:=x^2*diff(y(x), x, x)+4*x*diff(y(x),x)-4*y=0;`

Find the equation that `u`

satisfies.

`RdOrder:=reduce_order(ode35, y(x) = x, u(t));`

The output is \[\color{blue}{ \begin{aligned} y =& \left(t \left({\color{gray}{\int}}u \left(t \right){\color{gray}{d}}t +\_\textit{C1} \right)\right)\boldsymbol{\mathrm{where}}\\ &\left[\left\{t \left(u_{t}\right)+6 u \left(t \right)=0\right\}, \left\{t =x , u \left(t \right)=\frac{x \left({y'}\right)-y}{x^{2}}\right\}, \left\{x =t , y =t \left({\color{gray}{\int}}u \left(t \right){\color{gray}{d}}t +\_\textit{C1} \right)\right\}\right] \end{aligned} }\]

You can see that the equation for \(u\) is \(t \left(u_{t}\right)+6 u \left(t \right)=0\), where \(u_t\) is \(v'(t)\).

We can solve for \(u\) and then find \(v\). Here, we use the operand extract command `op`

to get the differential equation for \(u\). The equation is the first element in the first list of the second vector of the right hand side of the output. We now get the equation for \(u(x)\).

`odeu:=subs(t=x, op([2, 1, 1], rhs(RdOrder)));`

Now we substitute \(t\) by \(x\) and solve for \(u\) and \(v\).

```
ux:=dsolve(odeu, u(x));
v:=int(ux, x);
```

Therefore, by the following command, we know that \(y_2(x)=\frac{c}{x^4}\).

`y[2](x):=x*v(x);`

Testing \(y_2\) using the following command shows that it is a solution.

`odetest(y(x)=y[2](x), ode35);`

To get the second solution \(y_2\) after obtained the differential equation for \(u\), one can also use the command

`buildsol(Reduced_Order_Equation, Particular_Solution_of_u)`

One can also find \(y_2\) without using

`DETools`

(see for example the Maple document on Linear Equations created by Prof. Douglas B. Meade.)

**Exercise 4.6 **The equation \(x^2y'' + 3xy' - 3y=0\) has a solution \(y_1=x\). Find another linearly independent solution \(y_2\).

## 4.6 Variation of Parameters

Maple has the command `varparam(Solutions, f(x), x)`

to find the general solution of a linear ODE by the method of variation of parameters, where \(f(x)\) is the right-hand side function. Again this command belongs to `DETools`

.

**Example 4.8 **Find the generals solution for the equation
\[x^2y'' + 4xy' - 4y=x\]
using the solutions \(y_1=x\) and \(y_2=\frac{1}{x^4}\) of the complementary equation
\[x^2y'' + 4xy' - 4y=0.\]

*Solution*. We can find the general solution using one line of command.

`DETools[varparam]([x, 1/x^4], x, x)`

The output is \[ \color{blue}{ \_C_{1} x +\frac{\_C_{2}}{x^{3}}+\frac{x^{3}}{14} } \]

**Exercise 4.7 **Find the generals solution for the equation
\[x^2y'' + 3xy' - 3y=x\]
using the solutions \(y_1=x\) and \(y_2=\frac{1}{x^3}\) of the complementary equation
\[x^2y'' + 3xy' - 3y=0.\]