Variation of Parameters
Undetermined coefficients only works for special right-hand sides. Variation of parameters finds a particular solution for any continuous forcing , and even for variable coefficients, as long as you know the homogeneous solutions. The price is two integrals that may be hard.
The idea
For with homogeneous solutions , , replace the constants in by functions:
Two unknown functions but one equation leave freedom for an extra condition. Choosing keeps free of terms, and substituting into the equation gives the linear system
whose matrix is the Wronskian matrix. By Cramer's rule, with :
The equation must be in standard form (coefficient of equal to 1) for to be the right function here.
Example:
On : , , .
import sympy as sp
x = sp.symbols("x")
y1, y2, f = sp.cos(x), sp.sin(x), sp.tan(x)
W = sp.simplify(sp.wronskian([y1, y2], x))
u1 = sp.integrate(-y2 * f / W, x)
u2 = sp.integrate(y1 * f / W, x)
yp = sp.simplify(u1 * y1 + u2 * y2)
print("W =", W)
print("y_p =", yp)
print("check:", sp.simplify(yp.diff(x, 2) + yp - f))W = 1
y_p = (log(sin(x) - 1) - log(sin(x) + 1))*cos(x)/2
check: 0
SymPy's antiderivative of may look different from , but the check confirms it.
A formula with a definite integral: Green's function
Using definite integrals from gives the particular solution with :
For the kernel is : the response at time to a kick at time . This is the convolution form you will meet again with the Laplace transform. It also works numerically for any , even measured data:
import numpy as np
from scipy.integrate import quad, solve_ivp
w = 2.0
f = lambda s: np.exp(-s) * np.sqrt(1 + s) # a forcing with no nice guess
yp = lambda x: quad(lambda s: np.sin(w * (x - s)) / w * f(s), 0, x)[0]
sol = solve_ivp(lambda t, Y: [Y[1], f(t) - w**2 * Y[0]], (0, 3), [0.0, 0.0],
t_eval=[1.0, 2.0, 3.0], rtol=1e-10, atol=1e-12)
for x, y in zip(sol.t, sol.y[0]):
print(f"x = {x}: Green's formula {yp(x):.8f}, ODE solver {y:.8f}")x = 1.0: Green's formula 0.28467486, ODE solver 0.28467486
x = 2.0: Green's formula 0.14711448, ODE solver 0.14711448
x = 3.0: Green's formula -0.23016075, ODE solver -0.23016075
Comparing the two methods
| Undetermined coefficients | Variation of parameters | |
|---|---|---|
| Coefficients | constant only | any, if , are known |
| Forcing | polynomials, exponentials, sines and products | any continuous |
| Work | linear algebra | two integrals (possibly hard) |
In software
- The Green's-function formula is how linear systems are simulated with measured inputs: the impulse response is convolved with the input signal. Audio reverb ("convolution reverb") does exactly this with a recorded impulse response of a room.
scipy.signal.lsimsimulates a linear system's response to an arbitrary input in the same spirit.
Exercises
Exercise 1: Wronskian first
For with , , compute and the formulas for and .
Answer
; , .
Solution
. and .
Exercise 2: Check against undetermined coefficients
Use variation of parameters for and compare with the guess .
Answer
either way.
Solution
, . Then . The guess gives , the same.
Exercise 3: Secant forcing (code)
Find a particular solution of on .
Answer
.
Solution
and .
import sympy as sp
x = sp.symbols("x")
yp = x * sp.sin(x) + sp.cos(x) * sp.log(sp.cos(x))
print(sp.simplify(yp.diff(x, 2) + yp - 1 / sp.cos(x)))0
Test yourself
Variation of parameters looks for of the form…
- with unknown functions
- a polynomial
- with constants
Before applying the formulas to , you must…
- nothing
- divide by so that
- multiply by
- differentiate
Which advantage does variation of parameters have over undetermined coefficients?
- It never needs integrals
- It works for any continuous forcing
- It doesn't need the homogeneous solutions
- It only uses algebra