§ Variation of Parameters

Variation of
Parameters

Undetermined coefficients breaks when the forcing gets ugly. This is the universal fallback — built from scratch, from pure logic. The constants become functions. Everything else follows.

From First Principles The Wronskian Machine Full Worked Examples Common Mistakes
scroll to begin

The Problem We're Solving

We want the full solution to a nonhomogeneous second-order linear ODE:

\[ y'' + p(x)\,y' + q(x)\,y = g(x) \]

We already know how to solve the associated homogeneous version (when the right side is zero). Suppose those two linearly independent solutions are \(y_1\) and \(y_2\). Then the homogeneous solution is:

\[ y_h = c_1 y_1 + c_2 y_2 \]

The question is: how do we find a particular solution \(y_p\) to the full forced equation?

Why Undetermined Coefficients Sometimes Fails

Undetermined coefficients works by guessing the shape of \(y_p\). That's great when differentiating the forcing function keeps producing the same "family" of functions — like \(e^x\), \(\sin x\), polynomials. But what happens when you differentiate \(\tan x\)?

You get \(\sec^2 x\). Differentiate that and you get something else entirely. The family never closes. There's no finite set of shapes to guess from. The photocopier is broken.

✗ Undetermined Coefficients Fails

Forcing functions that generate infinitely many new shapes when differentiated:

\(\tan x,\quad \sec x,\quad \ln x,\quad \dfrac{1}{x},\quad e^x \ln x\)

✓ Variation of Parameters Always Works

Any continuous forcing function \(g(x)\). No restrictions on form. Universal method.

The Big Idea — Let the Constants Move

Here is the core insight. Think about the homogeneous solution:

\[ y_h = c_1 y_1 + c_2 y_2 \]

The constants \(c_1, c_2\) are fixed numbers. They don't change. That's exactly what makes it the homogeneous solution — the fixed weights just combine two natural modes of the system.

But what if the system is being driven by an external force \(g(x)\)? A fixed weight can't respond to a moving driver. So the idea is:

💡 The Variation Idea

For the forced equation, let those constants become functions of \(x\):

\[ c_1 \;\to\; u_1(x), \qquad c_2 \;\to\; u_2(x) \]

So we try \(y_p = u_1(x)\,y_1(x) + u_2(x)\,y_2(x)\) — the same structure as the homogeneous solution, but with adaptive weights. The structure absorbs the forcing. The weights track it.

This is not a guess pulled from thin air. It is motivated by the structure of the problem. The homogeneous basis \(\{y_1, y_2\}\) already spans all solutions to the unforced system — so any particular solution to the forced system should live in the same neighborhood, just with coefficients that adapt to the forcing.

Building the Machine from Scratch

We want to find \(u_1(x)\) and \(u_2(x)\) such that

\[ y_p = u_1 y_1 + u_2 y_2 \]

satisfies \(y'' + p(x)y' + q(x)y = g(x)\). To do that, we differentiate \(y_p\) twice and substitute.

Step 1 — First Derivative

Apply the product rule on every term:

\(y_p = u_1 y_1 + u_2 y_2\)
Our ansatz
\(y_p' = u_1' y_1 + u_1 y_1' + u_2' y_2 + u_2 y_2'\)
Product rule on each term
\(y_p' = \underbrace{u_1' y_1 + u_2' y_2}_{\text{set this to } 0} + u_1 y_1' + u_2 y_2'\)
Group the "new" terms

Notice we have four terms. If we differentiate again as-is, the next derivative will have eight terms, and the algebra becomes a complete swamp. So we impose a deliberate simplifying condition:

🎯 The Gauge Condition (Our Clever Choice)

We freely impose:

\[ u_1' y_1 + u_2' y_2 = 0 \]

This is not a constraint forced on us by the physics — it is a choice we make to keep the algebra clean. We have two unknown functions \(u_1, u_2\), which means we need two equations to determine them. The ODE will give us one. This condition is the second. We're using our freedom wisely.

With that condition, the first derivative simplifies beautifully:

\[ y_p' = u_1 y_1' + u_2 y_2' \]

Step 2 — Second Derivative

Now differentiate the simplified \(y_p'\):

\(y_p' = u_1 y_1' + u_2 y_2'\)
From gauge simplification
\(y_p'' = u_1' y_1' + u_1 y_1'' + u_2' y_2' + u_2 y_2''\)
Product rule again

So now we have a clean inventory of all three quantities we need:

\(y_p = u_1 y_1 + u_2 y_2\)
\(y_p' = u_1 y_1' + u_2 y_2'\) gauge applied
\(y_p'' = u_1' y_1' + u_2' y_2' + u_1 y_1'' + u_2 y_2''\)

Step 3 — Substitute into the ODE

Plug everything into \(y'' + py' + qy = g\):

\((u_1' y_1' + u_2' y_2' + u_1 y_1'' + u_2 y_2'') + p(u_1 y_1' + u_2 y_2') + q(u_1 y_1 + u_2 y_2) = g\)
Direct substitution
\(u_1' y_1' + u_2' y_2' + u_1\underbrace{(y_1'' + py_1' + qy_1)}_{=\,0} + u_2\underbrace{(y_2'' + py_2' + qy_2)}_{=\,0} = g\)
Group by \(u_1\) and \(u_2\)
\(u_1' y_1' + u_2' y_2' = g\)
\(y_1, y_2\) solve homogeneous → their groups vanish

The magic just happened. Because \(y_1\) and \(y_2\) are solutions to the homogeneous equation, the giant grouped expressions vanish identically. All the structure collapses, and we're left with a simple second equation.

💡 Why the Homogeneous Terms Vanish

We know \(y_1'' + py_1' + qy_1 = 0\) because \(y_1\) is a homogeneous solution — it was built to satisfy exactly that. Same for \(y_2\). So when we substitute \(y_p\) into the full ODE, those terms are identically zero. The forcing function \(g(x)\) is the only thing left.

The 2×2 System — Enter the Wronskian

We now have exactly two equations for two unknowns \(u_1'(x)\) and \(u_2'(x)\):

\(u_1' y_1 + u_2' y_2 = 0\) gauge condition
\(u_1' y_1' + u_2' y_2' = g\) from ODE substitution

This is a straightforward linear system. Write it in matrix form:

\[ \begin{pmatrix} y_1 & y_2 \\ y_1' & y_2' \end{pmatrix} \begin{pmatrix} u_1' \\ u_2' \end{pmatrix} = \begin{pmatrix} 0 \\ g \end{pmatrix} \]

The determinant of the coefficient matrix is exactly the Wronskian:

\[ W = W(y_1, y_2) = \begin{vmatrix} y_1 & y_2 \\ y_1' & y_2' \end{vmatrix} = y_1 y_2' - y_2 y_1' \]
📐 What the Wronskian Actually Measures

Think of \(y_1\) and \(y_2\) as two vectors in function space. The Wronskian measures how "different" they are — their linear independence. If \(W \neq 0\), the two functions span a 2D space and you can uniquely write any solution as a combination of them. If \(W = 0\), they're essentially the same solution in disguise, and the matrix can't be inverted.

This is precisely why \(W \neq 0\) is required: we need to invert the system. No independence → no inversion → no solution. Game over.

Solving with Cramer's Rule

To solve a 2×2 system \(A\mathbf{x} = \mathbf{b}\), Cramer's rule says: replace each column of \(A\) with the right-hand side vector \(\mathbf{b}\) and divide by \(\det(A)\).

For \(u_1'\) — replace the first column:

\(u_1' = \dfrac{\begin{vmatrix} 0 & y_2 \\ g & y_2' \end{vmatrix}}{W}\)
Cramer's rule, column 1
\(= \dfrac{0 \cdot y_2' - g \cdot y_2}{W}\)
Expand the 2×2 determinant
\(\boxed{u_1' = -\dfrac{y_2\, g}{W}}\)
Result for u₁'

For \(u_2'\) — replace the second column:

\(u_2' = \dfrac{\begin{vmatrix} y_1 & 0 \\ y_1' & g \end{vmatrix}}{W}\)
Cramer's rule, column 2
\(= \dfrac{y_1 \cdot g - 0 \cdot y_1'}{W}\)
Expand the 2×2 determinant
\(\boxed{u_2' = \dfrac{y_1\, g}{W}}\)
Result for u₂'
⚠️ Sign Asymmetry — Don't Mix These Up

\(u_1'\) has a minus sign because the right-hand side \((0, g)^T\) hits column 1's position differently in the determinant expansion. \(u_2'\) does not. This asymmetry comes from the Cramer's rule expansion — it is baked into the structure, not a typo.

The Variation of Parameters Formulas

Now integrate \(u_1'\) and \(u_2'\) to get the weight functions:

\(u_1 = -\displaystyle\int \dfrac{y_2\, g}{W}\,dx\)
Integrate u₁'
\(u_2 = \phantom{-}\displaystyle\int \dfrac{y_1\, g}{W}\,dx\)
Integrate u₂'

Then the particular solution is:

\[ y_p = u_1 y_1 + u_2 y_2 = -y_1 \int \frac{y_2\, g}{W}\,dx \;+\; y_2 \int \frac{y_1\, g}{W}\,dx \]

And the full general solution is:

🏆 Master Formula — Variation of Parameters \[ \boxed{y = c_1 y_1 + c_2 y_2 - y_1 \int \frac{y_2\, g}{W}\,dx + y_2 \int \frac{y_1\, g}{W}\,dx} \]

Valid when: \(y'' + p(x)y' + q(x)y = g(x)\), \(W(y_1,y_2) \neq 0\) on the interval

Why the Gauge Condition Was Legitimate

You might be skeptical: we just imposed the condition \(u_1' y_1 + u_2' y_2 = 0\). Isn't that cheating?

No. Here's the key insight:

💡 Counting Degrees of Freedom

We introduced two unknown functions \(u_1(x)\) and \(u_2(x)\). To uniquely determine two functions, we need exactly two equations. The ODE supplies one (after substitution). The gauge condition is the second — it's a free choice we make to tame the algebra.

This is the same spirit as choosing a coordinate system in physics. The physics doesn't care which coordinates you use — you choose the ones that make the problem cleanest. The gauge condition is our clever coordinate choice.

Without it, variation of parameters would still work in principle, but differentiating \(y_p'\) the second time would produce many extra terms involving \(u_1''\) and \(u_2''\), and the system would become far more complicated. The condition eliminates this mess without changing the solution space.

In physics, this kind of freedom-fixing is called a gauge choice — the same idea underlies how you fix the gauge in electromagnetism. The name "variation of parameters" could almost be "variation with gauge freedom."

The Step-by-Step Recipe

When you see \(y'' + p(x)y' + q(x)y = g(x)\), do this:

Put in standard form

Make sure the coefficient of \(y''\) is exactly 1. If it's \(a(x)\), divide through first. The \(g(x)\) in the formula is \(r(x)/a(x)\), not \(r(x)\).

Solve the homogeneous equation

Find two linearly independent solutions \(y_1\) and \(y_2\) from the characteristic equation or known methods.

Compute the Wronskian

\(W = y_1 y_2' - y_2 y_1'\). Check it's nonzero on your interval.

Compute \(u_1'\) and \(u_2'\)

\(u_1' = -y_2 g / W\) and \(u_2' = y_1 g / W\). Don't drop the minus sign on \(u_1'\).

Integrate both

\(u_1 = \int u_1'\,dx\) and \(u_2 = \int u_2'\,dx\). Drop constants of integration — they'll merge into \(c_1, c_2\) in \(y_h\).

Build \(y_p = u_1 y_1 + u_2 y_2\)

Simplify. If any pieces of \(y_p\) are already in \(y_h\), absorb them — they're redundant.

Write the full solution \(y = y_h + y_p\)

Include all arbitrary constants \(c_1, c_2\) from \(y_h\). Apply initial conditions if given.

Example 1 — Why \(\tan x\) Breaks Undetermined Coefficients

This example is the canonical reason variation of parameters exists. The forcing function \(\tan x\) has no closed finite derivative family.

Example 1 Solve \(\;y'' + y = \tan x\) ▼ Show Solution

Step A — Identify Standard Form

Compare with \(y'' + p(x)y' + q(x)y = g(x)\):

\[ p(x) = 0, \qquad q(x) = 1, \qquad g(x) = \tan x \]

The coefficient of \(y''\) is already 1. We're in standard form.

Step B — Homogeneous Solution

Solve \(y'' + y = 0\). Characteristic equation:

\(r^2 + 1 = 0\)
Characteristic equation
\(r = \pm i\)
Pure imaginary roots
\(y_h = c_1\cos x + c_2\sin x\)
Complex root → trig form

So \(y_1 = \cos x\) and \(y_2 = \sin x\).

Step C — Wronskian

\(W = \begin{vmatrix} \cos x & \sin x \\ -\sin x & \cos x \end{vmatrix}\)
Build the determinant
\(W = \cos^2 x + \sin^2 x = 1\)
Pythagorean identity cleans it up

The Wronskian equals 1 everywhere. This is as clean as it gets.

Step D — Compute \(u_1'\)

\(u_1' = -\dfrac{y_2\, g}{W} = -\dfrac{\sin x \cdot \tan x}{1}\)
Formula with W = 1
\(u_1' = -\sin x \cdot \dfrac{\sin x}{\cos x} = -\dfrac{\sin^2 x}{\cos x}\)
Substitute \(\tan x = \sin x / \cos x\)
\(u_1' = -\dfrac{1 - \cos^2 x}{\cos x} = -\sec x + \cos x\)
Use \(\sin^2 x = 1 - \cos^2 x\), split fraction

Now integrate:

\(u_1 = \displaystyle\int (-\sec x + \cos x)\,dx\)
Integrate term by term
\(u_1 = -\ln|\sec x + \tan x| + \sin x\)
\(\int \sec x\,dx = \ln|\sec x + \tan x|\)

Step E — Compute \(u_2'\)

\(u_2' = \dfrac{y_1\, g}{W} = \dfrac{\cos x \cdot \tan x}{1}\)
Formula with W = 1
\(u_2' = \cos x \cdot \dfrac{\sin x}{\cos x} = \sin x\)
Cosines cancel perfectly
\(u_2 = \displaystyle\int \sin x\,dx = -\cos x\)
Standard integral

Step F — Build \(y_p\)

\(y_p = u_1 y_1 + u_2 y_2\)
Assemble
\(y_p = (-\ln|\sec x + \tan x| + \sin x)\cos x + (-\cos x)\sin x\)
Substitute
\(y_p = -\cos x\ln|\sec x + \tan x| + \sin x\cos x - \sin x\cos x\)
Distribute
\(y_p = -\cos x\ln|\sec x + \tan x|\)
Last two terms cancel — beautiful

Final Answer

\[ y = c_1\cos x + c_2\sin x - \cos x\ln|\sec x + \tan x| \]

The log term comes from the integral of \(\sec x\) — exactly the kind of "exotic" term that undetermined coefficients would never produce. This is variation of parameters being necessary, not just convenient.

Example 2 — Resonance Without Effort

This example shows something slick: the forcing function \(e^x\) is already part of the homogeneous solution. Undetermined coefficients would require a resonance fix (multiply the guess by \(x\)). Variation of parameters handles this automatically — no special casing needed.

Example 2 Solve \(\;y'' - y = e^x\) ▼ Show Solution

Step A — Homogeneous Solution

\(r^2 - 1 = 0 \;\Rightarrow\; r = \pm 1\)
Characteristic equation, real roots
\(y_h = c_1 e^x + c_2 e^{-x}\)
Two exponential solutions

So \(y_1 = e^x\) and \(y_2 = e^{-x}\). Notice \(g(x) = e^x = y_1\). This is resonance territory.

Step B — Wronskian

\(W = \begin{vmatrix} e^x & e^{-x} \\ e^x & -e^{-x} \end{vmatrix}\)
Build the determinant
\(W = e^x(-e^{-x}) - e^{-x}(e^x) = -1 - 1 = -2\)
Expand and simplify

Step C — Compute \(u_1'\)

\(u_1' = -\dfrac{y_2\, g}{W} = -\dfrac{e^{-x} \cdot e^x}{-2}\)
Substitute \(y_2, g, W\)
\(u_1' = -\dfrac{1}{-2} = \dfrac{1}{2}\)
\(e^{-x} \cdot e^x = 1\), two negatives cancel
\(u_1 = \dfrac{x}{2}\)
Integrate the constant

Step D — Compute \(u_2'\)

\(u_2' = \dfrac{y_1\, g}{W} = \dfrac{e^x \cdot e^x}{-2} = -\dfrac{e^{2x}}{2}\)
Substitute
\(u_2 = -\dfrac{1}{2}\int e^{2x}\,dx = -\dfrac{1}{4}e^{2x}\)
\(\int e^{2x}\,dx = \tfrac{1}{2}e^{2x}\)

Step E — Build \(y_p\)

\(y_p = u_1 y_1 + u_2 y_2 = \dfrac{x}{2}e^x + \left(-\dfrac{1}{4}e^{2x}\right)e^{-x}\)
Assemble
\(y_p = \dfrac{x}{2}e^x - \dfrac{1}{4}e^x\)
\(e^{2x} \cdot e^{-x} = e^x\)
🎯 Absorbing Redundant Terms

The term \(-\tfrac{1}{4}e^x\) is already a homogeneous solution (it's a multiple of \(y_1 = e^x\)). It belongs in \(y_h\), not \(y_p\). Since \(c_1 e^x\) already captures it, we can absorb this term there — leaving the cleanest possible particular solution.

\(y_p = \dfrac{x}{2}e^x\)
After absorbing the redundant term

Look at the form: \(x e^x\). This is exactly the "resonance guess" you'd have needed in undetermined coefficients. Variation of parameters produced it automatically from the integral \(\int \tfrac{1}{2}\,dx = \tfrac{x}{2}\).

Final Answer

\[ y = c_1 e^x + c_2 e^{-x} + \frac{x}{2}e^x \]
💡 Why Resonance Is Automatic

In undetermined coefficients, resonance requires a special rule: if your guess overlaps with \(y_h\), multiply by \(x\). In variation of parameters, there is no special rule — the algebra produces the \(x\) factor naturally through the integration step. The method doesn't know or care about resonance; it just works.

VoP Solution Explorer

This explorer solves \(y'' + \omega^2 y = A\sin(\beta x)\) using variation of parameters numerically. Adjust the parameters to see how the particular solution tracks the forcing.

⚡ Variation of Parameters — Solution Explorer
Natural frequency \(\omega\) 1.0
Forcing amplitude \(A\) 1.0
Forcing frequency \(\beta\) 0.5
...

\(y_h\) (homogeneous)   \(y_p\) (particular)   \(y\) (full solution)

Common Mistakes — and Why They Happen

⚠️ Mistake 1 — Using Non-Standard Form

The formulas \(u_1' = -y_2 g/W\) and \(u_2' = y_1 g/W\) require the equation to be in standard form with leading coefficient 1. If your equation is \(a(x)y'' + b(x)y' + c(x)y = r(x)\), you must divide through by \(a(x)\) first. The \(g\) in the formula is \(r(x)/a(x)\), not \(r(x)\).

⚠️ Mistake 2 — Dropping the Minus Sign on \(u_1'\)

The formula is \(u_1' = -y_2 g / W\). That minus sign is structural — it comes from the Cramer's rule expansion of the first column. \(u_2'\) has no minus. Every time you write these down, double-check the sign on \(u_1'\).

⚠️ Mistake 3 — Using Dependent Solutions

If \(y_1\) and \(y_2\) are linearly dependent (one is just a multiple of the other), the Wronskian is zero and the system cannot be solved. You need a genuine fundamental set — two genuinely different solutions spanning the solution space.

⚠️ Mistake 4 — Keeping Homogeneous Pieces in \(y_p\)

If any term in your \(y_p\) is of the form \(C \cdot y_1\) or \(C \cdot y_2\), absorb it into the \(c_1, c_2\) constants in \(y_h\). Particular solutions are not unique — you want the cleanest one. Keeping extra homogeneous pieces in \(y_p\) isn't wrong, but it's messy and confusing.

📋 Quick Method Comparison
Undetermined Coefficients Variation of Parameters
Speed Fast when it works More computation
Scope Limited forcing functions Any continuous \(g(x)\)
Resonance Special rule required Automatic
Variable coefficients No Yes (if \(y_1, y_2\) are known)

Everything in One Place

Variation of parameters works because of this chain of logic:

🏆 The Full Machine \[ y'' + p(x)y' + q(x)y = g(x) \] \[ W = y_1 y_2' - y_2 y_1' \] \[ u_1' = -\frac{y_2\,g}{W} \qquad u_2' = \frac{y_1\,g}{W} \] \[ \boxed{y = c_1 y_1 + c_2 y_2 \;-\; y_1\!\int \frac{y_2\,g}{W}\,dx \;+\; y_2\!\int \frac{y_1\,g}{W}\,dx} \]

Checklist for Any Problem

Before Starting

① Standard form (leading coeff = 1)
② Identify \(y_1, y_2\) from homogeneous
③ Verify \(W \neq 0\)

During Computation

④ Minus sign on \(u_1'\) — always
⑤ Drop integration constants (merge into \(c_1, c_2\))
⑥ Simplify \(y_p\) fully before adding \(y_h\)

When to Use VoP

Forcing is \(\tan x\), \(\sec x\), \(\ln x\), \(1/x\), or anything UC can't guess

When to Use UC Instead

Forcing has a finite derivative family: \(e^{ax}\), \(\sin bx\), \(\cos bx\), polynomials, products of these