variation of parameters
/ var-ee-AY-shun of pa-RAM-eh-ters /
Undetermined coefficients is fast but picky — it only handles a short list of nice forcings. Variation of parameters is the universal tool: it builds a particular solution for ANY continuous forcing g(x), even messy ones like tan(x) or sec(x) where guessing has no chance. The price is doing two integrals, which may or may not be elementary.
The clever idea is in the name. You already have two homogeneous solutions y1 and y2, so y_c = c1 y1 + c2 y2 with CONSTANTS c1, c2. The method says: let those constants VARY — replace them by unknown functions u1(x) and u2(x) and seek y_p = u1 y1 + u2 y2. Imposing one convenient extra condition to keep the algebra clean (namely u1' y1 + u2' y2 = 0) reduces everything to two equations for u1' and u2'. Solving them gives u1' = -y2 g / W and u2' = y1 g / W, where W = y1 y2' - y2 y1' is the Wronskian of y1 and y2. Integrate u1' and u2', plug back, and y_p = u1 y1 + u2 y2 is your particular solution.
Because it never guesses, variation of parameters works whenever you have a fundamental set y1, y2 of the homogeneous equation and g is continuous — it even handles variable-coefficient equations once you can solve the homogeneous part. Its only catch is honesty about integration: the formulas are guaranteed, but the resulting integrals can be hard or impossible to express in elementary terms. For the short list of textbook forcings, undetermined coefficients is usually quicker; for everything else, variation of parameters is what you reach for.
For y'' + y = sec(x), here y1 = cos(x), y2 = sin(x), W = 1. Then u1' = -sin(x) sec(x) = -tan(x) and u2' = cos(x) sec(x) = 1. Integrating, u1 = ln|cos(x)| and u2 = x, so y_p = cos(x) ln|cos(x)| + x sin(x) — a forcing undetermined coefficients cannot touch.
Let the constants become functions; the Wronskian formulas hand you u1' and u2'.
The Wronskian formulas assume the equation is in standard form y'' + p y' + q y = g with leading coefficient 1; divide through by the leading coefficient first or the g in the formulas will be wrong.