On this page
Undetermined coefficients handles right-hand sides like e^(5x), x² or sin 2x well. Give it y″ + y = sec x and it stalls. Variation of parameters does not guess the shape of the answer: it builds the particular solution from the two homogeneous solutions and two integrals.
Why does undetermined coefficients fail for y″ + y = sec x?
Undetermined coefficients guesses a particular solution shaped like the right-hand side, so it needs a function whose derivatives stay in a small family. Paul Dawkins' notes at Lamar University put the limit plainly: the method "will only work for a fairly small class of g(t)'s" (Paul's Online Notes).
The function sec x is outside that class. Its derivative is sec x tan x, the next is sec x tan²x + sec³x, and new terms keep appearing. Lecture notes from Purdue University try the guess Y = A sec t and note "Changed form!" when they differentiate it (Purdue MA 366, Lesson 18). For the guessing method in full, see how to use the method of undetermined coefficients.
How does variation of parameters work?
Start from y″ + y = 0, whose solutions are y₁ = cos x and y₂ = sin x (if that step is new, read how to solve second-order linear differential equations). Variation of parameters replaces the constants with functions: y_p = u₁(x)y₁ + u₂(x)y₂.
That is two unknown functions but only one equation they must satisfy. So we add a second condition, u₁′y₁ + u₂′y₂ = 0. Substituting y_p into y″ + y = g(x) then leaves two linear equations:
u₁′y₁ + u₂′y₂ = 0
u₁′y₁′ + u₂′y₂′ = g(x)
Solving them gives the Wronskian formulas u₁′ = −y₂g/W and u₂′ = y₁g/W, with W = y₁y₂′ − y₁′y₂, as stated in the Purdue notes (Purdue MA 366, Lesson 18). The method was first sketched by Leonhard Euler and completed by Joseph-Louis Lagrange, who first used it in 1766 (Wikipedia: Variation of parameters).
Why is the extra condition allowed?
We need one particular solution, not all of them, and the single requirement that y_p solves the equation is met by infinitely many pairs u₁, u₂. Trench's textbook on LibreTexts says u₁ and u₂ "have to satisfy only one condition", so a second can be imposed that "produces a convenient simplification" (LibreTexts, Trench 5.7/05%3A_Linear_Second_Order_Equations/5.07%3A_Variation_of_Parameters)).
With u₁′y₁ + u₂′y₂ = 0, the derivative y_p′ = u₁y₁′ + u₂y₂′ looks as if u₁ and u₂ were constants, so y_p″ contains only first derivatives of u₁ and u₂, never second. The two equations have determinant W, which is never zero on an interval where y₁ and y₂ are independent solutions, so they always give exactly one u₁′ and one u₂′.
Worked example: solving y″ + y = sec x
Homogeneous solutions: y₁ = cos x, y₂ = sin x, and g(x) = sec x.
Wronskian: W = cos x · cos x − (−sin x) · sin x = cos²x + sin²x = 1.
Parameter derivatives: u₁′ = −sin x · sec x = −tan x, and u₂′ = cos x · sec x = 1.
Integrate: u₁ = ln|cos x| and u₂ = x. Leave out the constants; they would only add another copy of c₁cos x + c₂sin x.
Particular solution: y_p = cos x ln|cos x| + x sin x.
General solution: y = c₁cos x + c₂sin x + x sin x + cos x ln|cos x|, on any interval where cos x ≠ 0, such as −π/2 < x < π/2.
This matches the answer in the Purdue lecture notes linked above.
How do you check the answer by substitution?
On −π/2 < x < π/2, cos x is positive, so write y_p = x sin x + cos x ln(cos x) and differentiate.
y_p′ = sin x + x cos x − sin x ln(cos x) − sin x = x cos x − sin x ln(cos x)
y_p″ = cos x − x sin x − cos x ln(cos x) + sin²x / cos x
Adding y_p cancels the x sin x and cos x ln(cos x) terms, leaving cos x + sin²x / cos x = (cos²x + sin²x) / cos x = sec x. The particular solution checks.
Practise the same routine on y″ + y = tan x or y″ + y = cosec x, where only the integrals change. The Fermi Problem Library has a step-by-step solver that explains the reasoning, so you can compare each line of your working, not just the final answer. If the Wronskian itself feels shaky, the Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing. For constant-coefficient equations with initial conditions, another route is the Laplace transform, worked by hand.



