TITLE: What is the quickest way to solve this 2nd Order Linear ODE?
QUESTION [5 upvotes]: This appeared on my professor's test review, and its taken me hours to, surprise surprise, get the wrong answer. Could someone help me with the method I should be using to solve this?
$$y^{\prime\prime}+y=\tan x$$

REPLY [3 votes]: The method below will solve equations of the form:

$$y'' + y = \frac{f'(x)}{\cos x}$$

First notice that $\displaystyle (h \cos x)'' = h'' \cos x - 2 h' \sin x - h \cos x$
Thus if $\displaystyle y = h \cos x$, then $\displaystyle y'' + y = h'' \cos x - 2h' \sin x$
Thus $\displaystyle (y'' + y')\cos x = h'' \cos^2 x - 2h' \sin x \cos x = (h' \cos^2 x)'$
Thus we get $$h' \cos^2 x = f(x) + A$$
And so 

$$y = \cos x  \int (f(x) + A)\sec^2 x \ \text{d}x$$

In your case, $\displaystyle f(x) =  - \cos x$ and so

$$y = \cos x \ \int (A - \cos x) \sec^2 x \ \text{d}x  = A\sin x -  \cos x \ \log (\sec x + \tan x) + B \cos x$$