Variation of Parameters

Variation of parameters finds a particular solution of y″ + p(x)y′ + q(x)y = g(x) from two homogeneous solutions y₁ and y₂. Write yₚ = u₁y₁ + u₂y₂, where u₁′ = −y₂g/W and u₂′ = y₁g/W and W is the Wronskian. It works for right sides like tan x or e^x/x, where undetermined coefficients fails.

Before this lesson: The Wronskian, Method of Undetermined Coefficients and Choosing an Integration Technique

The idea: let the constants vary

The complementary solution y_c = C₁y₁ + C₂y₂ solves the equation with 0 on the right. To get the right side g(x), replace the constants with functions and try yₚ = u₁(x)y₁ + u₂(x)y₂. The constants (parameters) now vary, which gives the method its name.

Two unknown functions need two conditions. The first is a choice that keeps the algebra simple: u₁′y₁ + u₂′y₂ = 0. Substituting yₚ into the equation then gives the second: u₁′y₁′ + u₂′y₂′ = g. Solving this 2 × 2 system with Cramer’s rule gives u₁′ and u₂′, and the denominator is the Wronskian W = y₁y₂′ − y₂y₁′.

Unlike undetermined coefficients, this method works for any continuous g(x), and even when p and q depend on x, as long as you know y₁ and y₂. The cost is two integrals, which can be hard.

Variation of parameters formula

For y″ + p(x)y′ + q(x)y = g(x) in standard form, with homogeneous solutions y₁ and y₂,

u_1' = -\dfrac{y_2\,g}{W}, \qquad u_2' = \dfrac{y_1\,g}{W}, \qquad W = y_1y_2' - y_2y_1'
y_p = -y_1\displaystyle\int \dfrac{y_2\,g}{W}\,dx + y_2\displaystyle\int \dfrac{y_1\,g}{W}\,dx

The coefficient of y″ must be 1. For ay″ + by′ + cy = f(x), divide by a first, so g = f/a.

How to use variation of parameters

  1. Put the equation in standard form and read off g(x).
  2. Solve the homogeneous equation for y₁ and y₂, and compute W.
  3. Compute u₁′ = −y₂g/W and u₂′ = y₁g/W.
  4. Integrate to get u₁ and u₂. You can drop the constants of integration.
  5. Write yₚ = u₁y₁ + u₂y₂, drop any terms that are already in y_c, and write y = y_c + yₚ.

Variation of parameters examples

Example 1: A tangent right side

Solve y″ + y = tan x for x between −π/2 and π/2.

y_1 = \cos x,\quad y_2 = \sin x

The roots of r² + 1 = 0 are ±i.

W = \cos x\cos x - \sin x(-\sin x) = 1

Compute the Wronskian and use cos²x + sin²x = 1.

u_1' = -\sin x\tan x = -\dfrac{\sin^2 x}{\cos x}

Use u₁′ = −y₂g/W.

u_1' = -\dfrac{1 - \cos^2 x}{\cos x} = \cos x - \sec x

Replace sin²x with 1 − cos²x (see fundamental trig identities) and split the fraction.

u_1 = \sin x - \ln(\sec x + \tan x)

Integrate; ∫sec x dx = ln|sec x + tan x|, and sec x + tan x is positive here (see trigonometric integrals).

u_2' = \cos x\tan x = \sin x

Use u₂′ = y₁g/W.

u_2 = -\cos x

Integrate.

y_p = \cos x\left[\sin x - \ln(\sec x + \tan x)\right] + \sin x(-\cos x)

Form u₁y₁ + u₂y₂.

y_p = -\cos x\ln(\sec x + \tan x)

Distribute; the sin x cos x terms cancel.

Answer: y = C₁ cos x + C₂ sin x − cos x ln(sec x + tan x).

Example 2: A repeated root and e^x/x

Solve y″ − 2y′ + y = e^x/x for positive x.

y_1 = e^{x},\quad y_2 = xe^{x}

The characteristic equation (r − 1)² = 0 has a repeated root.

W = e^{x}(1 + x)e^{x} - xe^{x}e^{x} = e^{2x}

Compute the Wronskian and combine like terms.

u_1' = -\dfrac{xe^{x}\cdot e^{x}/x}{e^{2x}} = -1

Use u₁′ = −y₂g/W and cancel.

u_1 = -x

Integrate.

u_2' = \dfrac{e^{x}\cdot e^{x}/x}{e^{2x}} = \dfrac{1}{x}

Use u₂′ = y₁g/W and cancel.

u_2 = \ln x

Integrate (see integrals that give natural logarithms).

y_p = -xe^{x} + xe^{x}\ln x

Form u₁y₁ + u₂y₂.

y_p = xe^{x}\ln x

Drop −xe^x, which is already in y_c.

Answer: y = (C₁ + C₂x)e^x + xe^x ln x. Undetermined coefficients has no trial form for e^x/x, so this method is the way to go.

Example 3: Checking against undetermined coefficients

Solve y″ − 3y′ + 2y = e^(3x) with variation of parameters, then check with undetermined coefficients.

y_1 = e^{x},\quad y_2 = e^{2x}

The characteristic equation (r − 1)(r − 2) = 0 has roots 1 and 2.

W = e^{x}\cdot 2e^{2x} - e^{2x}\cdot e^{x} = e^{3x}

Compute the Wronskian.

u_1' = -\dfrac{e^{2x}e^{3x}}{e^{3x}} = -e^{2x} \Rightarrow u_1 = -\tfrac{1}{2}e^{2x}

Use u₁′ = −y₂g/W, cancel and integrate.

u_2' = \dfrac{e^{x}e^{3x}}{e^{3x}} = e^{x} \Rightarrow u_2 = e^{x}

Use u₂′ = y₁g/W, cancel and integrate.

y_p = -\tfrac{1}{2}e^{3x} + e^{3x} = \tfrac{1}{2}e^{3x}

Form u₁y₁ + u₂y₂ and combine like terms.

9A - 9A + 2A = 1 \Rightarrow A = \tfrac{1}{2}

Check: substitute Ae^(3x) and divide by e^(3x).

Answer: y = C₁e^x + C₂e^(2x) + ½e^(3x). Both methods agree, but undetermined coefficients is faster when it applies.

Example 4: Variable coefficients

For positive x, y₁ = x and y₂ = x² solve x²y″ − 2xy′ + 2y = 0. Find a particular solution of x²y″ − 2xy′ + 2y = x³.

y'' - \dfrac{2}{x}y' + \dfrac{2}{x^2}y = x

Divide by x² for standard form, so g = x.

W = x(2x) - x^2(1) = x^2

Compute the Wronskian.

u_1' = -\dfrac{x^2\cdot x}{x^2} = -x \Rightarrow u_1 = -\dfrac{x^2}{2}

Use u₁′ = −y₂g/W and integrate.

u_2' = \dfrac{x\cdot x}{x^2} = 1 \Rightarrow u_2 = x

Use u₂′ = y₁g/W and integrate.

y_p = -\dfrac{x^2}{2}\cdot x + x\cdot x^2 = \dfrac{x^3}{2}

Form u₁y₁ + u₂y₂ and combine like terms.

Answer: y = C₁x + C₂x² + x³/2. Check: yₚ′ = 3x²/2 and yₚ″ = 3x, so x²(3x) − 2x(3x²/2) + 2(x³/2) = 3x³ − 3x³ + x³ = x³. Forgetting to divide by x² would give g = x³ and a wrong answer.

Example 5: A spring pushed by a growing force (word problem)

An undamped spring starts at rest at its rest position. A motor pushes it with a force that grows as time goes on, and its position x (in meters, t in seconds) satisfies x″ + x = sec t for t between 0 and π/2, with x(0) = 0 and x′(0) = 0. Find x(t) and the position at t = 1.

u_1' = -\sin t\sec t = -\tan t

With x₁ = cos t, x₂ = sin t and W = 1, use u₁′ = −x₂g/W.

u_1 = \ln(\cos t)

Integrate; cos t is positive here.

u_2' = \cos t\sec t = 1 \Rightarrow u_2 = t

Use u₂′ = x₁g/W and integrate.

x_p = \cos t\ln(\cos t) + t\sin t

Form u₁x₁ + u₂x₂.

x = C_1\cos t + C_2\sin t + \cos t\ln(\cos t) + t\sin t

Add x_c.

C_1 = 0

Substitute t = 0: ln(cos 0) = ln 1 = 0.

x_p' = -\sin t\ln(\cos t) - \sin t + \sin t + t\cos t

Differentiate xₚ with the product rule and the chain rule.

x' = C_2\cos t - \sin t\ln(\cos t) + t\cos t

Combine like terms and add the derivative of C₂ sin t.

C_2 = 0

Substitute t = 0 into x′.

x(1) = \cos 1\ln(\cos 1) + \sin 1 \approx -0.3326 + 0.8415

Substitute t = 1 with a calculator in radian mode.

x(1) \approx 0.509

Add.

Answer: x(t) = cos t ln(cos t) + t sin t, and x(1) ≈ 0.509 m. Here the particular solution already matches both initial conditions, so x_c drops out.

Graph of x(t) = cos t ln(cos t) + t sin t for t from 0 to 1.5 seconds. The solid curve starts at 0 with a flat start, curves upward, passes through the marked point (1, 0.509) and reaches about 1.31 at t = 1.5. A dashed curve, the term t sin t, starts at 0 and stays above the solid curve, ending at about 1.50.
Starting from rest, the spring moves out as the force sec t grows. The solid curve stays below the dashed t sin t term because cos t ln(cos t) is negative.

Common mistakes

MistakeExample of the errorFix
Skipping standard formUsing g = x³ for x²y″ − 2xy′ + 2y = x³Divide by x² first: g = x.
Mixing up the signsu₁′ = y₂g/WThe minus sign goes on u₁′ = −y₂g/W.
Pairing the wrong functionsu₁′ = −y₁g/Wu₁′ uses y₂ and u₂′ uses y₁.
Forgetting Wu₂′ = y₁gDivide by W, even when it is not 1.
Stopping at u₁ and u₂Giving u₂ = ln x as the answerThe answer is yₚ = u₁y₁ + u₂y₂, plus y_c.
Sign error integrating tan xWriting ∫tan x dx = ln(cos x)∫tan x dx = −ln|cos x|, so ∫(−tan x) dx = ln|cos x|.

Related ideas

Variation of parameters vs. undetermined coefficients

Undetermined coefficientsVariation of parameters
Right side g(x)Polynomials, exponentials, sines, cosines and their productsAny continuous g(x)
CoefficientsConstants onlyCan depend on x, if y₁ and y₂ are known
WorkAlgebra (match coefficients)Two integrals

When g(x) fits the table in Method of Undetermined Coefficients, that method is usually faster. Example 3 shows the two agree.

Where the formula comes from

The two conditions u₁′y₁ + u₂′y₂ = 0 and u₁′y₁′ + u₂′y₂′ = g form a linear system in u₁′ and u₂′. Its coefficient determinant is the Wronskian from The Wronskian lesson, which is not 0 for a fundamental set, so the system always has one solution.

Equations with variable coefficients

Variation of parameters needs y₁ and y₂ first. For equations like x²y″ + bxy′ + cy = 0, Cauchy-Euler Equations shows how to find them, and Reduction of Order finds y₂ from y₁.

Practice problems

  1. Find a particular solution of y″ + y = sec x for x between −π/2 and π/2.
  2. Find a particular solution of y″ + y = csc x for x between 0 and π.
  3. Find a particular solution of y″ + 4y = sec 2x for x between −π/4 and π/4.
  4. Use variation of parameters to find a particular solution of y″ − y = e^x.
  5. Find a particular solution of y″ + 2y′ + y = e^(−x)/x² for positive x.
  6. Find a particular solution of y″ − 4y′ + 4y = e^(2x)/(1 + x²).
  7. Use variation of parameters to find a particular solution of y″ + y = sin x.
  8. For positive x, y₁ = x² and y₂ = x² ln x solve x²y″ − 3xy′ + 4y = 0. Find a particular solution of x²y″ − 3xy′ + 4y = x².
  9. For positive x, y₁ = e^x and y₂ = x + 1 solve xy″ − (x + 1)y′ + y = 0. Find a particular solution of xy″ − (x + 1)y′ + y = x².
  10. Solve y″ + y = tan x with y(0) = 1 and y′(0) = 0, for x between −π/2 and π/2.
Show answers

1.

u_1' = -\sin x\sec x = -\tan x \Rightarrow u_1 = \ln(\cos x)

y₁ = cos x, y₂ = sin x, W = 1; cos x is positive here.

u_2' = \cos x\sec x = 1 \Rightarrow u_2 = x

Use u₂′ = y₁g/W and integrate.

Answer: yₚ = cos x ln(cos x) + x sin x

2.

u_1' = -\sin x\csc x = -1 \Rightarrow u_1 = -x

y₁ = cos x, y₂ = sin x, W = 1.

u_2' = \cos x\csc x = \cot x \Rightarrow u_2 = \ln(\sin x)

Integrate; sin x is positive here.

Answer: yₚ = −x cos x + sin x ln(sin x)

3.

W = \cos 2x(2\cos 2x) - \sin 2x(-2\sin 2x) = 2

y₁ = cos 2x, y₂ = sin 2x.

u_1' = -\dfrac{\sin 2x\sec 2x}{2} = -\tfrac{1}{2}\tan 2x \Rightarrow u_1 = \tfrac{1}{4}\ln(\cos 2x)

Use u₁′ = −y₂g/W and integrate with u = 2x.

u_2' = \dfrac{\cos 2x\sec 2x}{2} = \tfrac{1}{2} \Rightarrow u_2 = \tfrac{x}{2}

Use u₂′ = y₁g/W and integrate.

Answer: yₚ = ¼ cos 2x ln(cos 2x) + ½ x sin 2x

4.

W = e^{x}(-e^{-x}) - e^{-x}e^{x} = -2

y₁ = e^x, y₂ = e^(−x).

u_1' = -\dfrac{e^{-x}e^{x}}{-2} = \tfrac{1}{2} \Rightarrow u_1 = \tfrac{x}{2}

Use u₁′ = −y₂g/W and integrate.

u_2' = \dfrac{e^{x}e^{x}}{-2} = -\tfrac{1}{2}e^{2x} \Rightarrow u_2 = -\tfrac{1}{4}e^{2x}

Use u₂′ = y₁g/W and integrate.

y_p = \tfrac{x}{2}e^{x} - \tfrac{1}{4}e^{x}

Form u₁y₁ + u₂y₂.

Answer: yₚ = ½xe^x (dropping −¼e^x, which is in y_c)

5.

W = e^{-x}(1 - x)e^{-x} - xe^{-x}(-e^{-x}) = e^{-2x}

y₁ = e^(−x), y₂ = xe^(−x).

u_1' = -\dfrac{1}{x} \Rightarrow u_1 = -\ln x

−y₂g/W = −xe^(−x)·e^(−x)/(x²e^(−2x)).

u_2' = \dfrac{1}{x^2} \Rightarrow u_2 = -\dfrac{1}{x}

y₁g/W = e^(−x)·e^(−x)/(x²e^(−2x)).

y_p = -e^{-x}\ln x - e^{-x}

Form u₁y₁ + u₂y₂.

Answer: yₚ = −e^(−x) ln x (dropping −e^(−x))

6.

u_1' = -\dfrac{x}{1 + x^2} \Rightarrow u_1 = -\tfrac{1}{2}\ln(1 + x^2)

y₁ = e^(2x), y₂ = xe^(2x), W = e^(4x); integrate with u = 1 + x².

u_2' = \dfrac{1}{1 + x^2} \Rightarrow u_2 = \arctan x

Integrate (see integrals that give inverse trig functions).

Answer: yₚ = e^(2x)(x arctan x − ½ ln(1 + x²))

7.

u_1' = -\sin^2 x = -\tfrac{1}{2} + \tfrac{1}{2}\cos 2x

W = 1; use the identity sin²x = (1 − cos 2x)/2.

u_1 = -\tfrac{x}{2} + \tfrac{1}{4}\sin 2x

Integrate.

u_2' = \sin x\cos x \Rightarrow u_2 = \tfrac{1}{2}\sin^2 x

Integrate with u = sin x.

y_p = -\tfrac{x}{2}\cos x + \tfrac{1}{2}\sin x\cos^2 x + \tfrac{1}{2}\sin^3 x

Form u₁y₁ + u₂y₂, using sin 2x = 2 sin x cos x.

y_p = -\tfrac{x}{2}\cos x + \tfrac{1}{2}\sin x

Factor ½ sin x and use cos²x + sin²x = 1.

Answer: yₚ = −½x cos x (dropping ½ sin x)

8.

y'' - \dfrac{3}{x}y' + \dfrac{4}{x^2}y = 1

Divide by x², so g = 1.

W = x^2(2x\ln x + x) - x^2\ln x(2x) = x^3

Compute the Wronskian.

u_1' = -\dfrac{\ln x}{x} \Rightarrow u_1 = -\tfrac{1}{2}(\ln x)^2

−y₂g/W = −x² ln x/x³; integrate with u = ln x.

u_2' = \dfrac{1}{x} \Rightarrow u_2 = \ln x

y₁g/W = x²/x³.

y_p = -\tfrac{1}{2}x^2(\ln x)^2 + x^2(\ln x)^2

Form u₁y₁ + u₂y₂.

Answer: yₚ = ½x²(ln x)²

9.

y'' - \dfrac{x + 1}{x}y' + \dfrac{1}{x}y = x

Divide by x, so g = x.

W = e^{x}(1) - (x + 1)e^{x} = -xe^{x}

Compute the Wronskian.

u_1' = (x + 1)e^{-x} \Rightarrow u_1 = -(x + 2)e^{-x}

−y₂g/W = (x + 1)x/(xe^x); integrate by parts.

u_2' = -1 \Rightarrow u_2 = -x

y₁g/W = e^x·x/(−xe^x).

y_p = -(x + 2) - x(x + 1) = -x^2 - 2x - 2

Form u₁y₁ + u₂y₂ and distribute.

y_p = -x^2

Drop −2x − 2 = −2(x + 1), a multiple of y₂.

Answer: yₚ = −x²

10.

y = C_1\cos x + C_2\sin x - \cos x\ln(\sec x + \tan x)

Use Example 1.

C_1 = 1

Substitute x = 0; ln(1 + 0) = 0.

y' = -C_1\sin x + C_2\cos x + \sin x\ln(\sec x + \tan x) - 1

Differentiate; the derivative of ln(sec x + tan x) is sec x, and cos x sec x = 1.

C_2 - 1 = 0 \Rightarrow C_2 = 1

Substitute x = 0 into y′.

Answer: y = cos x + sin x − cos x ln(sec x + tan x)

Variation of parameters FAQ

What is variation of parameters?

It is a method for finding a particular solution of a linear nonhomogeneous differential equation. You replace the constants in y_c = C₁y₁ + C₂y₂ with functions u₁ and u₂ and solve for their derivatives.

What is the variation of parameters formula?

For y″ + py′ + qy = g, use yₚ = u₁y₁ + u₂y₂ with u₁′ = −y₂g/W and u₂′ = y₁g/W, where W = y₁y₂′ − y₂y₁′.

When should I use variation of parameters instead of undetermined coefficients?

Use it when g(x) is not a polynomial, exponential, sine, cosine or a product of these, such as tan x, sec x, ln x or 1/x, or when the coefficients depend on x.

Do I need the constants of integration for u₁ and u₂?

No. Constants of integration only add multiples of y₁ and y₂, which are already in y_c.

Summary

  • Write the equation in standard form y″ + py′ + qy = g.
  • Find y₁, y₂ and the Wronskian W = y₁y₂′ − y₂y₁′.
  • u₁′ = −y₂g/W and u₂′ = y₁g/W; integrate both.
  • yₚ = u₁y₁ + u₂y₂, and y = y_c + yₚ.
  • It works for any continuous g(x), but the integrals can be hard.

Previous lesson: Method of Undetermined Coefficients

Next lesson: Cauchy-Euler Equations

Back to the Differential Equations Index