TExcelTAD
Home › Differential Equations › Second-Order Linear ODEs

Second-Order Linear ODEs

A second-order linear equation has the form

y′′+p(x) y′+q(x) y=f(x).y'' + p(x)\,y' + q(x)\,y = f(x).

Springs, pendulums at small angles, electrical circuits and beams all lead to it. Before learning to solve particular cases, this lesson sets up the theory that makes every method work: superposition, linear independence and the Wronskian.

Homogeneous equations and superposition

When f=0f = 0 the equation is homogeneous. Write L[y]=y′′+py′+qyL[y] = y'' + py' + qy. The operator LL is linear: L[c1y1+c2y2]=c1L[y1]+c2L[y2]L[c_1y_1 + c_2y_2] = c_1L[y_1] + c_2L[y_2]. Hence

Superposition. If y1y_1 and y2y_2 solve L[y]=0L[y] = 0, so does every combination c1y1+c2y2c_1y_1 + c_2y_2.

For example, y′′+y=0y'' + y = 0 is solved by cos⁡x\cos x and sin⁡x\sin x, hence by every c1cos⁡x+c2sin⁡xc_1\cos x + c_2\sin x.

Existence and uniqueness

If pp, qq and ff are continuous on an interval II containing x0x_0, then for any numbers aa, bb the problem L[y]=fL[y] = f, y(x0)=ay(x_0) = a, y′(x0)=by'(x_0) = b has exactly one solution, and it exists on all of II. Unlike nonlinear equations, linear equations never blow up inside an interval where the coefficients are continuous.

Linear independence and the general solution

Two solutions y1y_1, y2y_2 are linearly independent if neither is a constant multiple of the other. Then the general solution of the homogeneous equation is

y=c1y1+c2y2,y = c_1 y_1 + c_2 y_2,

because we can match any initial values y(x0)=ay(x_0) = a, y′(x0)=by'(x_0) = b by solving the 2×22 \times 2 system

[y1(x0)y2(x0)y1′(x0)y2′(x0)][c1c2]=[ab].\begin{bmatrix} y_1(x_0) & y_2(x_0) \\ y_1'(x_0) & y_2'(x_0) \end{bmatrix} \begin{bmatrix} c_1 \\ c_2 \end{bmatrix} = \begin{bmatrix} a \\ b \end{bmatrix}.

The determinant of that matrix is the Wronskian W(y1,y2)=y1y2′−y1′y2W(y_1, y_2) = y_1y_2' - y_1'y_2. For two solutions of the same equation, WW is either zero everywhere or never zero, and it is nonzero exactly when the solutions are independent.

python · try it yourself
import sympy as sp

x = sp.symbols("x")
pairs = [(sp.cos(x), sp.sin(x)), (sp.exp(x), sp.exp(-x)), (sp.exp(2*x), 3*sp.exp(2*x))]
for y1, y2 in pairs:
    W = sp.simplify(sp.wronskian([y1, y2], x))
    print(f"W({y1}, {y2}) = {W}")
W(cos(x), sin(x)) = 1
W(exp(x), exp(-x)) = -2
W(exp(2*x), 3*exp(2*x)) = 0

The last pair is dependent: 3e2x3e^{2x} is a multiple of e2xe^{2x}, and the Wronskian is 0.

Matching initial conditions

Take y′′−y=0y'' - y = 0 with solutions exe^x, e−xe^{-x} and initial values y(0)=2y(0) = 2, y′(0)=−1y'(0) = -1. The system is c1+c2=2c_1 + c_2 = 2, c1−c2=−1c_1 - c_2 = -1:

python · try it yourself
import numpy as np

A = np.array([[1.0, 1.0], [1.0, -1.0]])      # rows: y(0), y'(0) of e^x and e^-x
c = np.linalg.solve(A, [2.0, -1.0])
print("c1, c2 =", c)
x = 1.0
print("y(1) =", round(c[0] * np.exp(x) + c[1] * np.exp(-x), 6))
c1, c2 = [0.5 1.5]
y(1) = 1.91096

Nonhomogeneous equations

If ypy_p is any one solution of L[y]=fL[y] = f, then every solution is

y=yp+c1y1+c2y2,y = y_p + c_1 y_1 + c_2 y_2,

because the difference of two solutions of L[y]=fL[y] = f solves L[y]=0L[y] = 0. Finding y1y_1, y2y_2 is the topic of the next two lessons; finding ypy_p is Undetermined Coefficients and Variation of Parameters.

Reduction of order

If you know one solution y1y_1, try y2=v(x) y1(x)y_2 = v(x)\,y_1(x). Substituting gives a first-order equation for v′v', whose solution is

y2=y1∫e−∫p dxy12 dx.y_2 = y_1 \int \frac{e^{-\int p\,dx}}{y_1^2}\,dx.

Example. x2y′′−3xy′+4y=0x^2y'' - 3xy' + 4y = 0 (x>0x > 0) has y1=x2y_1 = x^2. In standard form p=−3/xp = -3/x, so e−∫p=x3e^{-\int p} = x^3 and y2=x2∫x3x4dx=x2ln⁡xy_2 = x^2\int \frac{x^3}{x^4}dx = x^2\ln x.

In software

  • Superposition is why linear systems are easy to simulate and analyse: engineers compute the response to simple inputs (steps, impulses, sine waves) and add them up. Audio filters, structural analysis (FEM) and control design all rely on it.
  • Solving for the constants from initial conditions is a small linear system, np.linalg.solve, the same operation that dominates large simulations.

Exercises

Exercise 1: Superposition

Verify that y=3cos⁡2x−sin⁡2xy = 3\cos 2x - \sin 2x solves y′′+4y=0y'' + 4y = 0, and find y(0)y(0) and y′(0)y'(0).

Answer

y(0)=3y(0) = 3, y′(0)=−2y'(0) = -2.

Solution

y′′=−12cos⁡2x+4sin⁡2x=−4yy'' = -12\cos 2x + 4\sin 2x = -4y. y′=−6sin⁡2x−2cos⁡2xy' = -6\sin 2x - 2\cos 2x, so y′(0)=−2y'(0) = -2.

Exercise 2: Wronskian

Compute W(e2x,xe2x)W(e^{2x}, xe^{2x}). Are the functions independent?

Answer

W=e4x≠0W = e^{4x} \ne 0: independent.

Solution

y1y2′−y1′y2=e2x(e2x+2xe2x)−2e2x⋅xe2x=e4xy_1y_2' - y_1'y_2 = e^{2x}(e^{2x} + 2xe^{2x}) - 2e^{2x}\cdot xe^{2x} = e^{4x}.

Exercise 3: Reduction of order (code)

Given y1=xy_1 = x solves x2y′′−xy′+y=0x^2y'' - xy' + y = 0 (x>0x > 0), find y2y_2 and check it with SymPy.

Answer

y2=xln⁡xy_2 = x\ln x.

Solution

p=−1/xp = -1/x, e−∫p=xe^{-\int p} = x, y2=x∫xx2dx=xln⁡xy_2 = x\int \frac{x}{x^2}dx = x\ln x.

python · try it yourself
import sympy as sp
x = sp.symbols("x", positive=True)
y2 = x * sp.log(x)
print(sp.simplify(x**2 * y2.diff(x, 2) - x * y2.diff(x) + y2))
0

Test yourself

If y1y_1 and y2y_2 solve y′′+py′+qy=0y'' + py' + qy = 0, which of these is also a solution?

  1. y1y2y_1y_2
  2. 5y1−2y25y_1 - 2y_2
  3. y12y_1^2
  4. y1+1y_1 + 1

Two solutions of the same second-order homogeneous equation are independent exactly when…

  1. their Wronskian is nonzero
  2. they are both nonzero
  3. they are equal at x=0x = 0
  4. they are polynomials

The general solution of L[y]=fL[y] = f is…

  1. ypy_p
  2. c1y1+c2y2c_1y_1 + c_2y_2
  3. yp+c1y1+c2y2y_p + c_1y_1 + c_2y_2
  4. yp⋅(c1y1+c2y2)y_p \cdot (c_1y_1 + c_2y_2)