Undetermined Coefficients
To solve we need one particular solution (Second-Order Linear ODEs). When is a polynomial, an exponential, a sine or cosine, or a product of these, a smart guess works: has the same shape as , with unknown coefficients that we determine by substitution.
The guess table
| Guess for | |
|---|---|
| polynomial of degree | |
| or | |
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 (by if that still collides, which happens for a double root).
Example: exponential forcing
. Guess : , so . The homogeneous roots are 2 and , giving
Example: polynomial forcing
. Guess : then , so , , , and .
SymPy can do the bookkeeping: substitute the guess, collect powers, solve for the coefficients.
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
. The guess fails: already solves the homogeneous equation, so substituting gives . Multiply by : . Then , so .
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 the guess gives .
When the method does not apply
Undetermined coefficients needs constant coefficients and a forcing from the table. For or 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 .
Answer
.
Solution
Guess a constant : .
Exercise 2: Choose the guess
Write the form of (without solving) for .
Answer
.
Solution
The basic guess is . But and solve the homogeneous equation, so multiply everything by .
Exercise 3: Full IVP (code)
Solve , , .
Answer
.
Solution
(since ). Then with and .
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 ?
For (and no resonance), the guess is…
Undetermined coefficients does not work for…