Variation of Parameters

April 13, 2026

Problem

Solve y'' + y = sec(x) using variation of parameters. Show why undetermined coefficients cannot handle sec(x), then derive the particular solution from the Wronskian.

Explanation

Why undetermined coefficients fails here

The right side g(x)=secxg(x) = \sec x has derivatives that generate ever more complicated expressions: ddxsecx=secxtanx,d2dx2secx=secx(sec2x+tan2x),\frac{d}{dx} \sec x = \sec x \tan x, \quad \frac{d^{2}}{dx^{2}} \sec x = \sec x (\sec^{2} x + \tan^{2} x), \ldots

Unlike polynomials, exponentials, and trig functions, the successive derivatives of secx\sec x don't close into a finite-dimensional span. No finite guess works. Undetermined coefficients is out; we need a more general method.

What variation of parameters does

Starting from the homogeneous solution yh=C1y1+C2y2y_h = C_1 y_1 + C_2 y_2, the idea is to replace the constants C1,C2C_1, C_2 with unknown functions u1(x),u2(x)u_1(x), u_2(x): yp(x)=u1(x)y1(x)+u2(x)y2(x).y_p(x) = u_1(x) \, y_1(x) + u_2(x) \, y_2(x).

We then pick the uiu_i to satisfy the full non-homogeneous ODE, plus one convenient extra constraint that keeps the algebra tidy.

For the ODE in standard form y+p(x)y+q(x)y=g(x)y'' + p(x) y' + q(x) y = g(x), the uiu_i must satisfy: u1y1+u2y2=0u_1' y_1 + u_2' y_2 = 0 u1y1+u2y2=g(x)u_1' y_1' + u_2' y_2' = g(x)

This is a 2x2 linear system in u1,u2u_1', u_2'. Its determinant is the Wronskian W(y1,y2)=y1y2y2y1W(y_1, y_2) = y_1 y_2' - y_2 y_1' (see #195). Cramer's rule gives u1=y2gW,u2=y1gW.u_1' = -\frac{y_2 \, g}{W}, \qquad u_2' = \frac{y_1 \, g}{W}.

Then integrate to get u1,u2u_1, u_2 — and yp=u1y1+u2y2y_p = u_1 y_1 + u_2 y_2.

Step-by-step solution

Step 1 — Standard form

y+y=secx.y'' + y = \sec x. Already standard; p(x)=0p(x) = 0, q(x)=1q(x) = 1, g(x)=secxg(x) = \sec x.

Step 2 — Homogeneous solution

r2+1=0    r=±ir^{2} + 1 = 0 \implies r = \pm i, so y1=cosxy_1 = \cos x, y2=sinxy_2 = \sin x.

Step 3 — Wronskian

W=y1y2y2y1=cosxcosxsinx(sinx)=cos2x+sin2x=1.W = y_1 y_2' - y_2 y_1' = \cos x \cdot \cos x - \sin x \cdot (-\sin x) = \cos^{2} x + \sin^{2} x = 1.

(Clean: the Wronskian of cos\cos and sin\sin is 11. Good omen.)

Step 4 — Compute u1u_1' and u2u_2'

u1=y2gW=sinxsecx1=sinxcosx=tanxu_1' = -\frac{y_2 \, g}{W} = -\frac{\sin x \cdot \sec x}{1} = -\frac{\sin x}{\cos x} = -\tan x u2=y1gW=cosxsecx1=1u_2' = \frac{y_1 \, g}{W} = \frac{\cos x \cdot \sec x}{1} = 1

Step 5 — Integrate

u1=tanxdx=lncosx+C3u_1 = \int -\tan x \, dx = \ln |\cos x| + C_3 u2=1dx=x+C4u_2 = \int 1 \, dx = x + C_4

The constants of integration C3,C4C_3, C_4 only contribute multiples of y1,y2y_1, y_2 respectively — they get absorbed into yhy_h. Drop them: take u1=lncosxu_1 = \ln|\cos x| and u2=xu_2 = x.

Step 6 — Assemble ypy_p and general solution

yp=u1y1+u2y2=cosxlncosx+xsinx.y_p = u_1 y_1 + u_2 y_2 = \cos x \cdot \ln|\cos x| + x \sin x.

General solution: y(x)=C1cosx+C2sinx+cosxlncosx+xsinx\boxed{\, y(x) = C_1 \cos x + C_2 \sin x + \cos x \, \ln|\cos x| + x \sin x \,}

Verification

Differentiate yp=cosxlncosx+xsinxy_p = \cos x \ln|\cos x| + x \sin x: yp=sinxlncosx+cosxsinxcosx+sinx+xcosxy_p' = -\sin x \ln|\cos x| + \cos x \cdot \frac{-\sin x}{\cos x} + \sin x + x \cos x =sinxlncosxsinx+sinx+xcosx=sinxlncosx+xcosx= -\sin x \ln|\cos x| - \sin x + \sin x + x \cos x = -\sin x \ln|\cos x| + x \cos x

yp=cosxlncosxsinxsinxcosx+cosxxsinxy_p'' = -\cos x \ln|\cos x| - \sin x \cdot \frac{-\sin x}{\cos x} + \cos x - x \sin x =cosxlncosx+sin2xcosx+cosxxsinx= -\cos x \ln|\cos x| + \frac{\sin^{2} x}{\cos x} + \cos x - x \sin x =cosxlncosx+sin2x+cos2xcosxxsinx= -\cos x \ln|\cos x| + \frac{\sin^{2} x + \cos^{2} x}{\cos x} - x \sin x =cosxlncosx+secxxsinx= -\cos x \ln|\cos x| + \sec x - x \sin x

Add ypy_p: yp+yp=(cosxlncosx+secxxsinx)+(cosxlncosx+xsinx)=secx  y_p'' + y_p = (-\cos x \ln|\cos x| + \sec x - x \sin x) + (\cos x \ln|\cos x| + x \sin x) = \sec x \; \checkmark

Why the "extra constraint" u1y1+u2y2=0u_1' y_1 + u_2' y_2 = 0?

When you compute ypy_p' using the product rule: yp=u1y1+u1y1+u2y2+u2y2=(u1y1+u2y2)+(u1y1+u2y2).y_p' = u_1' y_1 + u_1 y_1' + u_2' y_2 + u_2 y_2' = (u_1' y_1 + u_2' y_2) + (u_1 y_1' + u_2 y_2').

Setting the first parenthetical to zero forces ypy_p' into the cleaner form u1y1+u2y2u_1 y_1' + u_2 y_2', which makes ypy_p'' manageable. Without this constraint, ypy_p'' would involve u1u_1'' and u2u_2'', creating a mess. It's not a sacrifice — the constraint reduces two unknowns (u1,u2)(u_1, u_2) to satisfying just two conditions, which is exactly right.

Advantages over undetermined coefficients

  • Works for any g(x)g(x) (as long as you can integrate yig/Wy_i \, g / W). No table of "acceptable" right-hand sides.
  • No resonance issue — the method naturally handles it because uiu_i are functions, not constants.
  • Unified — one recipe regardless of what gg looks like.

Downside: you have to integrate, which can be hard or intractable in closed form. For textbook gg's like polynomials and exponentials, undetermined coefficients is usually faster.

General-order statement

For an nn-th order linear ODE y(n)+=g(x)y^{(n)} + \ldots = g(x) with homogeneous basis {y1,,yn}\{y_1, \ldots, y_n\}, the method generalises: solve the n×nn \times n system uiyi(k),  k=0,,n1u_i' y_i^{(k)}, \; k = 0, \ldots, n-1 (the Wronskian matrix is the coefficient matrix, and its determinant is W(y1,,yn)W(y_1, \ldots, y_n)). Cramer's rule gives each uiu_i' as a ratio involving modified Wronskians.

Common mistakes

  • Forgetting to divide the RHS into standard form. If the leading coefficient is not 11, divide first so that gg means what the formula expects.
  • Dropping the absolute value in lncosx\ln|\cos x|. The domain where cosx>0\cos x > 0 (e.g. x<π/2|x| < \pi/2) lets you skip it, but in general keep it.
  • Confusing ypy_p's integration constants with those in yhy_h. The integration constants from u1,u2u_1, u_2 fold into yhy_h's constants — don't double-count.
  • Computing u1y1u_1' y_1 instead of u1y1u_1 y_1 in the final ypy_p. The integrand is u1u_1'; the thing you plug into ypy_p is u1u_1 (the integrated version).

Try it in the visualization

Switch g(x)g(x) between a sin\sin (handled by undetermined coefficients) and a sec\sec (handled only by variation of parameters). Watch the particular solution emerge from the Wronskian integral; overlay the homogeneous + particular decomposition so you can see each piece.

Interactive Visualization

Parameters

0.50
0.00
1.40
5.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Variation of Parameters | MathSpin