Differential Equations
Variation of Parameters
The universal recipe for a particular solution to Ly = f, when f is anything you like
For a non-homogeneous linear ODE Ly = f, variation of parameters constructs a particular solution by promoting the constants of the homogeneous general solution to functions of x. Starting from homogeneous solutions y₁, y₂, the new particular solution is y_p = c₁(x) y₁(x) + c₂(x) y₂(x); a 2×2 system whose determinant is the Wronskian solves for c'₁, c'₂, and integration finishes the job. The technique works for any forcing — including sec(x), tan(x), 1/x — where undetermined coefficients has no trial form.
- Formy'' + P(x) y' + Q(x) y = f(x)
- Ansatzy_p = c₁(x) y₁(x) + c₂(x) y₂(x)
- WronskianW(y₁, y₂) = y₁ y'₂ − y'₁ y₂
- Solve via Cramerc'₁ = −y₂ f / W, c'₂ = y₁ f / W
- CostO(n) extra ODE solves vs algebraic for undetermined coefs
- Used forForcings like sec(x), tan(x), 1/x, ln(x), data-driven f
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
The idea
Suppose you have already solved the homogeneous version of the ODE:
y'' + P(x) y' + Q(x) y = 0
and have two linearly independent solutions y₁(x), y₂(x). The homogeneous general solution is c₁ y₁ + c₂ y₂ with constants c₁, c₂. Now add a forcing term to get the non-homogeneous problem
y'' + P(x) y' + Q(x) y = f(x)
and look for a particular solution. Lagrange's idea (1774): assume y_p has the same shape as the homogeneous solution, but with the constants promoted to functions of x:
y_p(x) = c₁(x) y₁(x) + c₂(x) y₂(x)
The two functions c₁(x), c₂(x) are the new unknowns. One linear ODE for one unknown function y_p has been replaced by one ODE for two unknown functions, which is under-determined — we need one extra constraint. A clever choice that simplifies the algebra is:
c'₁ y₁ + c'₂ y₂ = 0 (constraint 1)
With that constraint, you can compute y'_p without second derivatives of ci: y'_p = c₁ y'₁ + c₂ y'₂. Differentiate once more, plug into the original ODE, simplify using Ly_i = 0, and you get
c'₁ y'₁ + c'₂ y'₂ = f(x) (constraint 2)
Now you have a 2×2 linear system for c'₁, c'₂:
[y₁ y₂ ] [c'₁] [ 0 ]
[y'₁ y'₂] [c'₂] = [f(x)]
The determinant of the coefficient matrix is the Wronskian W = y₁ y'₂ − y'₁ y₂. By Cramer's rule,
c'₁ = −y₂ f / W, c'₂ = y₁ f / W
Integrate, plug back into y_p, done.
The final formula
For a second-order linear ODE y'' + P(x) y' + Q(x) y = f(x) with homogeneous solutions y₁, y₂ and Wronskian W = y₁ y'₂ − y'₁ y₂,
y_p(x) = −y₁(x) ∫ (y₂(x') f(x') / W(x')) dx' + y₂(x) ∫ (y₁(x') f(x') / W(x')) dx'
The general solution is y = c₁ y₁ + c₂ y₂ + y_p, with c₁, c₂ now arbitrary constants determined by initial conditions.
Important. The formula assumes the coefficient of y'' has been normalised to 1. If your ODE is a(x) y'' + b(x) y' + c(x) y = g(x), divide through by a(x) first so that f(x) = g(x)/a(x) is the correct right-hand side.
Worked example — y'' + y = sec(x)
Step 1: solve the homogeneous equation. y'' + y = 0 has characteristic polynomial r² + 1 = 0 with roots r = ±i, so y₁ = cos x, y₂ = sin x.
Step 2: compute the Wronskian.
W = cos x · cos x − (−sin x) · sin x = cos²x + sin²x = 1
So W = 1 — the Wronskian is constant.
Step 3: assemble the formula. With f(x) = sec x = 1/cos x,
y_p = −cos x · ∫ (sin x · sec x / 1) dx + sin x · ∫ (cos x · sec x / 1) dx
Simplify the integrands:
- sin x · sec x = sin x / cos x = tan x
- cos x · sec x = 1
Step 4: integrate. ∫ tan x dx = −ln|cos x|. ∫ 1 dx = x.
Step 5: substitute.
y_p = −cos x · (−ln|cos x|) + sin x · x
= cos x · ln|cos x| + x sin x
General solution.
y = c₁ cos x + c₂ sin x + cos x · ln|cos x| + x sin x
Why undetermined coefficients failed. sec(x) is not a polynomial, exponential, sine, or cosine — the trial-form catalogue has no entry. Variation of parameters does not care about the structure of f — it just needs you to compute two integrals.
Derivation in detail
Start from the ansatz y_p = c₁ y₁ + c₂ y₂ with ci functions. Differentiate:
y'_p = c'₁ y₁ + c'₂ y₂ + c₁ y'₁ + c₂ y'₂
The first two terms are the awkward ones. Impose the constraint c'₁ y₁ + c'₂ y₂ = 0 — a free choice we make to keep the algebra tidy. Then
y'_p = c₁ y'₁ + c₂ y'₂
Differentiate again:
y''_p = c'₁ y'₁ + c'₂ y'₂ + c₁ y''₁ + c₂ y''₂
Plug y_p, y'_p, y''_p into y'' + P y' + Q y = f:
[c'₁ y'₁ + c'₂ y'₂] + [c₁ (y''₁ + P y'₁ + Q y₁)] + [c₂ (y''₂ + P y'₂ + Q y₂)] = f
The bracketed expressions on the right of each ci are zero because yi satisfies the homogeneous equation. What survives is
c'₁ y'₁ + c'₂ y'₂ = f
which is constraint 2. Together with constraint 1 we have the 2×2 linear system. Determinant is W; Cramer's rule gives the c'i. Integration produces ci, and y_p follows.
Higher-order and matrix-form variants
- n-th order. For an n-th order linear ODE with homogeneous basis y₁, …, yn and Wronskian W, the formula generalises: y_p = Σ yi ∫ (Wi f / W) dx, where Wi is the n×n Wronskian determinant with the i-th column replaced by (0, …, 0, 1)T.
- Variable-coefficient form. The technique requires P(x), Q(x) to be continuous and yi to be known — it does not give you the homogeneous solutions; you must already have them by characteristic roots, series methods, or known special functions.
- Matrix / system form. For a first-order system y' = A(x) y + f(x) with fundamental matrix Φ(x), the particular solution is y_p = Φ(x) ∫ Φ⁻¹(x') f(x') dx'. The 2×2 Wronskian system is the scalar disguise of this matrix formula.
- Green's function. Variation of parameters can be repackaged as y_p(x) = ∫ G(x, x') f(x') dx', where G(x, x') is the Green's function of the operator L. Same formula, different bookkeeping.
- Duhamel's principle. The PDE analogue: for an inhomogeneous linear evolution equation, integrate the homogeneous propagator against the forcing — again, the same structural idea generalised to PDE.
Variation of parameters vs alternatives
| Technique | Form of f(x) handled | Cost | Limitation |
|---|---|---|---|
| Undetermined coefficients | Polynomials, exponentials, sines, cosines, products thereof | Solve a small linear system in constants | Fails for f like sec(x), tan(x), 1/x, ln(x) |
| Variation of parameters | Any continuous f | Two extra integrals per particular solution | Need homogeneous basis y₁, y₂ first |
| Green's function | Any continuous f | Integrate against G(x, x') | Need G — once-and-done for a given operator |
| Laplace transform | Most f with simple transforms | Algebra in s-domain | Constant-coefficient ODEs only |
| Numerical (RK4) | Any f, including no closed form | O(N) steps for N grid points | No symbolic answer |
| Series solution | Analytic f | Tedious by hand | Convergence issues outside a disk |
Common pitfalls
- Forgetting to normalise the leading coefficient. The formula assumes y'' + P y' + Q y = f. If your ODE has a(x) y'' on the left, divide through by a(x) first — otherwise f in the formula is wrong by a factor of a(x).
- Picking the wrong sign on c'₁. By Cramer's rule c'₁ = −y₂ f / W (with the minus sign) and c'₂ = +y₁ f / W. Mixing them up makes the algebra not just wrong but plausible-looking.
- Mis-computing the Wronskian. W = y₁ y'₂ − y'₁ y₂ (note the order). Sign-flipping gives the negative Wronskian, and your final answer flips sign.
- Using ci(x) with the integration constant of integration. The constants of integration in ∫ c'i dx are absorbed into the c₁, c₂ of the homogeneous part. You can drop them in the particular solution.
- Skipping linear independence of y₁, y₂. If the homogeneous basis is dependent, the Wronskian is zero and Cramer's rule fails. Always confirm W ≠ 0 on the interval of interest.
- Reaching for variation of parameters when undetermined coefficients works. The latter is faster because you avoid integrals. Reserve variation of parameters for forcings that defeat the trial-form catalogue.
Frequently asked questions
What is variation of parameters?
A method that turns the constants of the homogeneous general solution c₁ y₁ + c₂ y₂ into functions of x and solves a 2×2 Wronskian system for c'₁, c'₂. Integration gives a particular solution of the non-homogeneous ODE.
When should I use it instead of undetermined coefficients?
When f(x) lies outside the trial-form catalogue (polynomials, exponentials, sines, cosines and their products). For sec(x), tan(x), 1/x, ln(x), or data-driven f, variation of parameters is the only general option.
What is the Wronskian and why does it appear?
W(y₁, y₂) = y₁ y'₂ − y'₁ y₂ is the determinant of the 2×2 linear system that variation of parameters has to solve. Cramer's rule then divides by W. By Abel's theorem, W ≠ 0 wherever y₁, y₂ are linearly independent.
What's the full formula?
y_p = −y₁ ∫ (y₂ f / W) dx + y₂ ∫ (y₁ f / W) dx, after normalising the ODE so the coefficient of y'' is 1.
Does it work for higher-order ODEs?
Yes. For n-th order, y_p = Σ yi ∫ (Wi f / W) dx, where Wi is the Wronskian with the i-th column replaced by (0, …, 0, 1)T. Practical hand-work tops out around n = 3.
What's the cost compared to undetermined coefficients?
Variation of parameters costs two extra integrals (n for n-th order) and works on any continuous f. Undetermined coefficients reduces to algebra and is faster when applicable but does not handle f like sec(x).