TExcelTAD
Home › Differential Equations › Undetermined Coefficients

Undetermined Coefficients

To solve ay′′+by′+cy=f(x)ay'' + by' + cy = f(x) we need one particular solution ypy_p (Second-Order Linear ODEs). When ff is a polynomial, an exponential, a sine or cosine, or a product of these, a smart guess works: ypy_p has the same shape as ff, with unknown coefficients that we determine by substitution.

The guess table

f(x)f(x) Guess for ypy_p
polynomial of degree nn Anxn+⋯+A1x+A0A_nx^n + \dots + A_1x + A_0
ekxe^{kx} AekxAe^{kx}
cos⁡ωx\cos\omega x or sin⁡ωx\sin\omega x Acos⁡ωx+Bsin⁡ωxA\cos\omega x + B\sin\omega x
xnekxx^ne^{kx} (Anxn+⋯+A0)ekx(A_nx^n + \dots + A_0)e^{kx}
ekxcos⁡ωxe^{kx}\cos\omega x ekx(Acos⁡ωx+Bsin⁡ωx)e^{kx}(A\cos\omega x + B\sin\omega x)

For a sum of such terms, guess the sum of the guesses.

The modification rule. If any term of the guess solves the homogeneous equation, multiply the whole guess by xx (by x2x^2 if that still collides, which happens for a double root).

Example: exponential forcing

y′′−y′−2y=4e3xy'' - y' - 2y = 4e^{3x}. Guess yp=Ae3xy_p = Ae^{3x}: 9A−3A−2A=4A=49A - 3A - 2A = 4A = 4, so A=1A = 1. The homogeneous roots are 2 and −1-1, giving

y=e3x+c1e2x+c2e−x.y = e^{3x} + c_1e^{2x} + c_2e^{-x}.

Example: polynomial forcing

y′′+4y=8x2y'' + 4y = 8x^2. Guess yp=Ax2+Bx+Cy_p = Ax^2 + Bx + C: then 2A+4Ax2+4Bx+4C=8x22A + 4Ax^2 + 4Bx + 4C = 8x^2, so A=2A = 2, B=0B = 0, C=−1C = -1, and yp=2x2−1y_p = 2x^2 - 1.

SymPy can do the bookkeeping: substitute the guess, collect powers, solve for the coefficients.

python · try it yourself
import sympy as sp

x, A, B, C = sp.symbols("x A B C")
yp = A * x**2 + B * x + C
residual = sp.expand(yp.diff(x, 2) + 4 * yp - 8 * x**2)
coeffs = sp.Poly(residual, x).all_coeffs()
print("equations:", coeffs)
print(sp.solve(coeffs, [A, B, C]))
equations: [4*A - 8, 4*B, 2*A + 4*C]
{A: 2, B: 0, C: -1}

Example: the modification rule

y′′−y′−2y=6e2xy'' - y' - 2y = 6e^{2x}. The guess Ae2xAe^{2x} fails: e2xe^{2x} already solves the homogeneous equation, so substituting gives 0=6e2x0 = 6e^{2x}. Multiply by xx: yp=Axe2xy_p = Axe^{2x}. Then yp′′−yp′−2yp=3Ae2xy_p'' - y_p' - 2y_p = 3Ae^{2x}, so A=2A = 2.

python · try it yourself
import sympy as sp

x = sp.symbols("x")
y = sp.Function("y")
for f in (6 * sp.exp(2 * x), 4 * sp.exp(3 * x), 10 * sp.sin(x)):
    sol = sp.dsolve(y(x).diff(x, 2) - y(x).diff(x) - 2 * y(x) - f, hint="nth_linear_constant_coeff_undetermined_coefficients")
    print(f"f = {f}:  y = {sol.rhs}")
f = 6*exp(2*x):  y = C2*exp(-x) + (C1 + 2*x)*exp(2*x)
f = 4*exp(3*x):  y = C1*exp(-x) + C2*exp(2*x) + exp(3*x)
f = 10*sin(x):  y = C1*exp(-x) + C2*exp(2*x) - 3*sin(x) + cos(x)

For f=10sin⁡xf = 10\sin x the guess Acos⁡x+Bsin⁡xA\cos x + B\sin x gives yp=cos⁡x−3sin⁡xy_p = \cos x - 3\sin x.

When the method does not apply

Undetermined coefficients needs constant coefficients and a forcing from the table. For f=tan⁡xf = \tan x or f=1xf = \frac{1}{x} there is no finite family of guesses; use Variation of Parameters or the Laplace transform.

In software

  • Steady-state responses of circuits and mechanical systems to sinusoidal inputs are found this way; it is the time-domain version of the phasor method in electrical engineering.
  • Computer algebra systems try undetermined coefficients first because it is cheap: one linear solve for the unknown coefficients.

Exercises

Exercise 1: Constant forcing

Find a particular solution of y′′+3y′+2y=10y'' + 3y' + 2y = 10.

Answer

yp=5y_p = 5.

Solution

Guess a constant AA: 2A=102A = 10.

Exercise 2: Choose the guess

Write the form of ypy_p (without solving) for y′′+9y=xcos⁡3xy'' + 9y = x\cos 3x.

Answer

yp=x[(Ax+B)cos⁡3x+(Cx+D)sin⁡3x]y_p = x\big[(Ax + B)\cos 3x + (Cx + D)\sin 3x\big].

Solution

The basic guess is (Ax+B)cos⁡3x+(Cx+D)sin⁡3x(Ax + B)\cos 3x + (Cx + D)\sin 3x. But cos⁡3x\cos 3x and sin⁡3x\sin 3x solve the homogeneous equation, so multiply everything by xx.

Exercise 3: Full IVP (code)

Solve y′′+y=exy'' + y = e^x, y(0)=0y(0) = 0, y′(0)=0y'(0) = 0.

Answer

y=12(ex−cos⁡x−sin⁡x)y = \frac{1}{2}(e^x - \cos x - \sin x).

Solution

yp=12exy_p = \frac{1}{2}e^x (since A+A=1A + A = 1). Then y=12ex+c1cos⁡x+c2sin⁡xy = \frac{1}{2}e^x + c_1\cos x + c_2\sin x with c1=−12c_1 = -\frac{1}{2} and 12+c2=0\frac{1}{2} + c_2 = 0.

python · try it yourself
import sympy as sp
x = sp.symbols("x"); y = sp.Function("y")
print(sp.dsolve(y(x).diff(x, 2) + y(x) - sp.exp(x), ics={y(0): 0, y(x).diff(x).subs(x, 0): 0}))
Eq(y(x), exp(x)/2 - sin(x)/2 - cos(x)/2)

Test yourself

What is the right guess for y′′−4y=e2xy'' - 4y = e^{2x}?

  1. Ae2xAe^{2x}
  2. Axe2xAxe^{2x}
  3. Ax2e2xAx^2e^{2x}
  4. Acos⁡2xA\cos 2x

For f(x)=3sin⁡2xf(x) = 3\sin 2x (and no resonance), the guess is…

  1. Asin⁡2xA\sin 2x
  2. Acos⁡2x+Bsin⁡2xA\cos 2x + B\sin 2x
  3. Asin⁡xA\sin x
  4. Ae2xAe^{2x}

Undetermined coefficients does not work for…

  1. y′′+y=x3y'' + y = x^3
  2. y′′+y=tan⁡xy'' + y = \tan x
  3. y′′+y=e−xcos⁡xy'' + y = e^{-x}\cos x
  4. y′′+y=5y'' + y = 5