Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 39 ยท Second-order Linear ODEs

Variation of Parameters

Learn variation of parameters for y'' + p y' + q y = g(t): derive the Wronskian formula, solve cases like tan t and 1/t where guessing fails, and verify with SymPy and SciPy.

Undetermined coefficients is quick but limited: it needs constant coefficients and a forcing term from a short list. Variation of parameters removes both restrictions. It works for any continuous g(t) and even for variable coefficients, as long as you already know two independent solutions of the homogeneous equation. The price is that you must compute some integrals.

The idea

For y'' + p(t)*y' + q(t)*y = g(t) (leading coefficient 1!), suppose y1 and y2 are independent solutions of the homogeneous equation. The homogeneous solution is C1*y1 + C2*y2 with constants. The trick is to let those "constants" vary: seek

y_p = u1(t)*y1(t) + u2(t)*y2(t).

Two unknown functions give us freedom to impose one extra condition. Choose it to keep the algebra clean: u1'*y1 + u2'*y2 = 0. Then y_p' = u1*y1' + u2*y2', and y_p'' = u1*y1'' + u2*y2'' + u1'*y1' + u2'*y2'. Substituting into the equation, the terms with u1 and u2 themselves cancel because y1, y2 solve the homogeneous equation, leaving u1'*y1' + u2'*y2' = g. So we have a 2-by-2 linear system for u1' and u2':

u1'*y1 + u2'*y2 = 0, u1'*y1' + u2'*y2' = g.

Cramer's rule gives, with the Wronskian W = y1*y2' - y2*y1',

u1' = -y2*g / W, u2' = y1*g / W.

Integrate each (constants of integration can be dropped: they only add pieces of y_h), and

y_p = -y1 * integral of (y2*g/W) dt + y2 * integral of (y1*g/W) dt.

Procedure

  1. Put the equation in standard form so that the coefficient of y'' is 1; then g is the right side of that form.
  2. Find y1, y2 and compute W.
  3. Compute u1' = -y2*g/W and u2' = y1*g/W, integrate.
  4. Form y_p = u1*y1 + u2*y2; the general solution is y_h + y_p.

Worked example: forcing tan t

y'' + y = tan(t), on -pi/2 < t < pi/2. Homogeneous solutions: y1 = cos t, y2 = sin t, W = cos**2 + sin**2 = 1. Then u1' = -sin(t)*tan(t) = -sin**2(t)/cos(t) = cos(t) - sec(t) and u2' = cos(t)*tan(t) = sin(t). Integrate: u1 = sin(t) - ln|sec t + tan t|, u2 = -cos(t). So

y_p = cos(t)*(sin t - ln|sec t + tan t|) - sin(t)*cos(t) = -cos(t)*ln|sec t + tan t|.

No guess of polynomial or trigonometric form could have found this.

Python Variation of parameters in SymPy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Example with a non-trigonometric forcing

y'' - 2*y' + y = e**t/t, t > 0. The homogeneous equation has a double root r = 1: y1 = e**t, y2 = t*e**t. The Wronskian: W = e**t*(1 + t)*e**t - t*e**t*e**t = e**(2*t). Then u1' = -t*e**t*(e**t/t)/e**(2*t) = -1 and u2' = e**t*(e**t/t)/e**(2*t) = 1/t. Thus u1 = -t, u2 = ln t, and y_p = -t*e**t + t*ln(t)*e**t = t*e**t*(ln t - 1). The -t*e**t part is a piece of y_h and may be dropped, so y_p = t*e**t*ln t is enough.

Python Check numerically against solve_ivp

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Variable coefficients

The method does not care whether coefficients are constant. For the Cauchy-Euler equation t**2*y'' - 2*y = t**2 (t > 0), the homogeneous solutions are t**2 and 1/t (try y = t**r: r*(r - 1) - 2 = 0, r = 2 or -1). Dividing by t**2 for standard form gives g = 1. With y1 = t**2, y2 = 1/t: W = t**2*(-1/t**2) - (1/t)*2*t = -3. Then u1' = -(1/t)*1/(-3) = 1/(3*t) and u2' = t**2/(-3), so u1 = ln(t)/3, u2 = -t**3/9, and y_p = t**2*ln(t)/3 - t**2/9. Again the t**2/9 part is homogeneous, so y_p = (t**2*ln t)/3 works.

Variation of parameters versus undetermined coefficients

Undetermined coefficients Variation of parameters
Coefficients constant any (given y1, y2)
Forcing exponential, polynomial, sin, cos any continuous g
Work algebra integrals
Resonance needs the t rule handled automatically

When both apply, undetermined coefficients is faster. Variation of parameters is the fallback that always works, and it leads to the Green's function and convolution formula seen in Laplace transform methods.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Before using the formulas u1' = -y2 g / W and u2' = y1 g / W, you must

    The derivation assumes y'' + p y' + q y = g, so g is the right side only after dividing by the leading coefficient.
  2. 2. For y'' + y = tan t the Wronskian of cos t and sin t is

    W = cos t * cos t - sin t * (-sin t) = cos2 t + sin2 t = 1.
  3. 3. Why can constants of integration in u1 and u2 be dropped?

    A constant c1 in u1 contributes c1*y1, which is a homogeneous solution already counted in y_h.
  4. 4. Variation of parameters applies to

    That is its main advantage over undetermined coefficients.

Summary

  • Seek y_p = u1*y1 + u2*y2 with u1'*y1 + u2'*y2 = 0.
  • Then u1' = -y2*g/W and u2' = y1*g/W, where W is the Wronskian and the equation has leading coefficient 1.
  • It works for any continuous forcing and for variable coefficients.
  • Integrals replace the guesswork; dropping integration constants is fine.
  • Use undetermined coefficients when it applies, and variation of parameters otherwise.

Next: Oscillators, Springs and Resonance