Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Initial value problems

We learned previously how to solve systems of first-order ODEs:

y=f(t,y)\vv{y}' = \vv{f}(t, \vv{y})

using Euler’s method. However, we didn’t learn what to do with higher-order derivatives. If a second-order ODE can be written in explicit form and as an initial value problem:

y=f(t,y,y),y(0)=y0,y(0)=y0y'' = f(t, y, y'), \quad y(0) = y_0, \quad y'(0) = y_0'

it can be solved by conversion to a system of first-order ODEs!

Let’s verify this works using an ODE that we can solve analytically. Consider:

y+y2y=0y(0)=4,y(0)=5y'' + y' - 2y = 0 \quad y(0) = 4, \quad y'(0) = -5

We previously showed using the characteristic polynomial that the solution to this IVP is:

y=ex+3e2xy = e^x + 3e^{-2x}

Now, let’s resolve by converting to a system. Let y1=yy_1 = y and y2=yy_2 = y'. Then, the ODE is equivalent to

y=2yyy2=2y1y2\begin{align} y'' &= 2y - y' \\ y_2' &= 2y_1 - y_2 \end{align}

and the system of ODEs is:

y1=y2,y1(0)=4y2=2y1+y2,y2(0)=5\begin{align} y_1' &= y_2, & y_1(0) &= 4 \\ y_2' &= 2y_1 + -y_2, & y_2(0) &= -5 \end{align}

This system of ODES is in the form y=Ay\vv{y}' = \vv{A}\vv{y} with

[0121]\begin{bmatrix} 0 & 1 \\ 2 & -1\end{bmatrix}

The eigenvalues of the matrix are

AλI=λ121λ=λ(λ+1)2=λ2+λ2=(λ1)(λ+2)=0\begin{align} |\vv{A}-\lambda \vv{I}| &=\begin{vmatrix}-\lambda & 1\\ 2& -1-\lambda \end{vmatrix} \\ &=\lambda(\lambda+1)-2 \\ &= \lambda^2 + \lambda - 2 \\ &= (\lambda-1)(\lambda+2) = 0 \end{align}

giving λ1=1\lambda_1 = 1 and λ2=2\lambda_2 = -2. The corresponding eigenvectors are:

Aλ1I=[1122]x1=[11]Aλ2I=[2121]x2=[12]\begin{align} \vv{A} - \lambda_1 \vv{I} &= \begin{bmatrix} -1 & 1 \\ 2 & -2 \end{bmatrix} \to \vv{x}_1 = \begin{bmatrix}1 \\ 1\end{bmatrix} \\ \vv{A} - \lambda_2 \vv{I} &= \begin{bmatrix} 2 & 1 \\ 2 & 1 \end{bmatrix} \to \vv{x}_2 = \begin{bmatrix}1 \\ -2\end{bmatrix} \end{align}

Hence,

y=c1ex[11]+c2e2x[12]\vv{y} = c_1 e^x \begin{bmatrix}1 \\ 1\end{bmatrix} + c_2 e^{-2x} \begin{bmatrix}1 \\ -2\end{bmatrix}

Apply the initial conditions by solving Xc=y(0)\vv{X} \vv{c} = \vv{y}(0)

[114125]R1R1[114039]R1÷3[114013]R2R2[101013]\begin{align} \begin{bmatrix}1 & 1 & 4 \\ 1 & -2 & -5 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ -R_1\end{matrix} &\to \begin{bmatrix}1 & 1 & 4 \\ 0 & -3 & -9 \end{bmatrix} \begin{matrix}\vphantom{R_1} \\ \div -3\end{matrix} \\ &\to \begin{bmatrix}1 & 1 & 4 \\ 0 & 1 & 3 \end{bmatrix} \begin{matrix} -R_2 \\ \vphantom{R_2}\end{matrix} \\ &\to \begin{bmatrix}1 & 0 & 1 \\ 0 & 1 & 3 \end{bmatrix} \end{align}

so

y=ex[11]+3e2x[12]\vv{y} = e^x \begin{bmatrix}1 \\ 1\end{bmatrix} + 3 e^{-2x} \begin{bmatrix}1 \\ -2\end{bmatrix}

or equivalently

y=y1=ex+3e2xy = y_1 = e^x + 3 e^{-2x}

The solution is the same as before! Note that in the process, we also obtained

y=y2=ex6e2xy' = y_2 = e^x - 6 e^{-2x}

which is consistent with direct differentiation of yy.

Example: Forced oscillator

A mass m on a Hookean spring (constant k) is experiences both a drag force (friction coefficient γ\gamma) and an oscillating external force FcosωtF \cos \omega t. Its position x obeys the differential equation

mx+γx+kx=Fcosωt,x(0)=x0,x(0)=v0m x'' + \gamma x' + kx = F \cos\omega t, \quad x(0) = x_0, \quad x'(0) = v_0

where x0x_0 and v0v_0 are the initial position and velocity of the mass. Write this second-order ODE as a system of first-order ODEs.


Let y1=xy_1 = x and y2=xy_2 = x'. Then, the ODE is equivalent to:

x=1m(kxγx+Fcosωt)y2=1m(ky1γy2+Fcosωt)\begin{align} x'' = \frac{1}{m}\left(- kx - \gamma x' + F\cos\omega t\right) \\ y_2' = \frac{1}{m}\left(- k y_1 - \gamma y_2 + F\cos \omega t \right) \end{align}

so

y1=y2,y1(0)=x0y2=1m(γy2ky1+Fcosωt),y2(0)=v0\begin{align} y_1' &= y_2, & y_1(0) &= x_0 \\ y_2' &= \displaystyle \frac{1}{m}\left(-\gamma y_2 - k y_1 + F\cos \omega t \right), & y_2(0) &= v_0 \end{align}

Boundary value problems

We can solve initial value problems for second-order ODEs by converting to a system and using methods we know. What about boundary value problems?

Let’s say we want to solve:

y+y=0,y(0)=0,y(π/6)=4y'' + y = 0, \quad y(0) = 0, \quad y(\pi/6) = 4

Using normal approach:

y=c1cosx+c2sinxy(0)=c1=0y(π/6)=c212=4c2=8\begin{align} y &= c_1 \cos x + c_2 \sin x \\ y(0) &= c_1 = 0\\ y(\pi/6) &= c_2 \frac{1}{2} = 4 \to c_2 = 8\\ \end{align}

so,

y=8sinxy = 8 \sin x

What if we needed to do this numerically? Try converting to system using y1=yy_1 = y and y2=yy_2 = y', so

y+y=0y2=y1y'' + y = 0 \to y_2' = -y_1

and

y1=y2,y1(0)=0y2=y1,y2(0)=a\begin{align} y_1' &= y_2, & y_1(0) &= 0 \\ y_2' &= -y_1, & y_2(0) &= a \end{align}

where a is an unknown value that we need to figure out so that y(π/6)=4y(\pi/6) = 4.

We will use the shooting method to determine a. The idea is to treat the boundary condition at the other value of x as a function of a, then vary a using a root-finding approach.

Graph of Lines

This boundary-condition function is the numerical integration of the system of ODEs! Bisection search is well-suited for solving for a because it is stable and doesn’t require a derivative.

Example: Reaction-diffusion with second-order reaction

We are solving a reaction-diffusion problem with a second-order reaction:

Dd ⁣2cd ⁣x2kc2=0,c(0)=c0,Dc(L)=0D \dd{2}{c}{x} - k c^2 = 0, \quad c(0) = c_0, \quad -D c'(L) = 0

Formulate in a form suitable for numerical solution using the shooting method.


First, rewrite as a system of first-order ODEs using y1=cy_1 = c and c2=cc_2 = c'. The ODE is

ckDc2y2=kDy12c'' - \frac{k}{D}c^2 \to y_2' = \frac{k}{D} y_1^2

so

y1=y2,y1(0)=c0y2=kDy1,y2(0)=a\begin{align} y_1' &= y_2, & y_1(0) &= c_0 \\ y_2' &= \frac{k}{D} y_1, & y_2(0) &= a \end{align}

where a is the unknown value of y2(0)y_2(0). Vary a until

Dc(L)=0y2(L)=0-D c'(L) = 0 \to y_2(L) = 0