solving $y''+y=\sec(x)$ I wish to find the solution of the differential equation: 
$$y''+y=\sec(x)$$
I know how to solve it using variation of parameters but I was wondering if it is possible to solve using undetermined coefficients.
Finding the homogeneous solution is easy, but is it possible to guess a private solution?   
 A: not that easy with variation of constant but direct integration is the easiest
$$y''+y=\sec(x)$$
$$y''\cos(x)-y'\sin(x)+y'\sin(x)+y\cos(x)=1$$
$$y'\cos(x)+y\sin(x)=x+K$$
$$(\frac y{\cos(x)})'=\frac {x+K}{\cos^2(x)}$$
$$\left (\frac y{\cos(x)}\right )=\int \frac {x+K}{\cos^2(x)}dx$$
$$y(x)=\cos(x)\int \frac {x}{\cos^2(x)}dx+K_1\sin(x)+K_2\cos(x)$$
$$y(x)=\cos(x)(x\tan(x)+\ln(\cos(x)))+K_1\sin(x)+K_2\cos(x)$$
$$y(x)=x\sin(x)+\cos(x)\ln(\cos(x))+K_1\sin(x)+K_2\cos(x)$$
Maybe the method with variation of constant will work with a correct substitution first...
A: Try $x\sin{x}+\cos{x}\ln\cos{x}$
A: We introduce :
$$ y=\lambda(x)y_1+\mu(x) y_2$$
where we want to determine $\lambda$ and $\mu$ , $y_1=\cos$ ,   $y_2=\sin $
$$ \begin{cases}
       \lambda'y_1+\mu' y_2=0\\
       \lambda'y_1'+\mu' y_2'=\sec\\
     \end{cases} $$ 
$$ \begin{cases}
       \lambda'y_1+\mu' y_2=0\\
       -\lambda'y_2+\mu' y_1=\sec\\
     \end{cases} $$ 
Then multiply by $\sin$ the first and $\cos$ the second:
$$ \begin{cases}
       \lambda'\cos\sin+\mu'\sin^2 =0\\
       -\lambda'\cos\sin+\mu'\cos^2=1\\
     \end{cases} $$ 
Combining line and using $ \cos^2 +\sin^2 =1 $ (Separate field of definiton for quotienting)
$$ \begin{cases}
       \mu'=1\\
       \lambda'=-\frac{\sin}{\cos\sin}\\
     \end{cases} $$ 
$$ \begin{cases}
       \mu=I_d+K_0\\
       \lambda'=-\frac{\sin}{\cos\sin}\\
     \end{cases} $$ 
So for $ \lambda '$
$$\lambda = \int \frac{2\sin}{\sin(2I_d)}$$
Using Bioche's Rules :
$$ \lambda= 2 \tanh^{-1}[\tan(\frac{Id}{2})] +K_1  $$ 
So you use 
$$ y:(x) \to (x+K_0)\sin(x)+2(\ln(\dfrac{1+\tan(\frac{I_d}{2})}{1-\tan(\frac{I_d}{2})}))+K_1)\cos(x) $$
A: You could use complex numbers as a tool to get to the answer.  First, we have $(D-i)(D+i) y = \sec x$.  Therefore, $(D+i)y = e^{ix} \int e^{-ix} \sec x \, dx = e^{ix} \int (1 - i \tan x) dx = x e^{ix} + i e^{ix} \ln |\cos x| + C e^{ix}$.  From there, we get $y = e^{-ix} \int (x e^{2ix} + i e^{2ix} \ln |\cos x| + C e^{2ix}) dx$.  Here, the first and third terms will be fairly easy.  To integrate $e^{2ix} \ln |\cos x|$ I would probably use integration by parts with $dv = e^{2ix}\,dx$ and $u = \ln |\cos x|$.
(Or otherwise, as a "dirty" trick, once you have $(D+i)y = x e^{ix} + i e^{ix} \ln |\cos x| + C e^{ix}$, if you expect to have $y$ being a real solution, then taking the imaginary parts of both sides will give $y = x \sin x + (\cos x) \ln |\cos x| + \tilde C_1 \sin x + \tilde C_2 \cos x$ where $\tilde C_1$ is the real part of $C$ and $\tilde C_2$ is the imaginary part.)
