2nd degree differential equation Can someone please tell me how to solve this differential equation?
$${d^2y\over dx^2} +y=\tan(x)$$
I am a beginner in ODE and have absolutely no idea how to proceed. 
Can you also site a reference to any special method(if used) that might be required to solve this easily? 
 A: $$\frac{d^2y}{dx^2} +y=\tan(x)$$


*

*The first task is to solve the related homogeneous equation :
$$\frac{d^2Y}{dx^2} +Y=0$$
I suppose that you can solve it.

*The second task is to find one particular solution of $\frac{d^2y_p}{dx^2} +y_p=\tan(x)$. The index $p$ means that we look for only one function (any one) among the infinity of functions $y$ which are solutions of the ODE.

*The third task it easy: $y=Y+y_p$ is the general solution which completely solve the problem.
The second task is the most difficult for you. It's surprising that such a problem is proposed to a "beginner in ODE".
HINT : You saw that a family of solutions of the homogeneous ODE is $\quad C\:\sin(x)\quad$. Remplace the constant $C$ by an unknown function $f(x)$. Then, put $y=f(x)\sin(x)$ into the ODE. It is transformed to another ODE where $f(x)$ is unknown. The advantage is that the new ODE can obviously be reduced to a first order linear ODE. It becomes much easier to solve than the initial second order ODE.
A: Following @JJacquelin, by variation of the constant, the equation becomes
$$\sin(x)f''(x)+2\cos(x)f'(x)-\sin(x)f(x)+\sin(x)f(x)=\tan(x).$$
Then with $g(x)=f'(x)$,
$$\sin(x)g'(x)+2\cos(x)g(x)=\tan(x).$$
We multiply by $\sin(x)$ to get an exact differential on the left
$$\sin(x)^2g'(x)+2\sin(x)\cos(x)g(x)=(\sin^2(x)g(x))'=\sin(x)\tan(x).$$
Now we integrate,
$$\sin^2(x)g(x)=\int\sin(x)\tan(x)\,dx=\int\frac{1-\cos^2(x)}{\cos(x)}dx=\int\left(\frac{\cos(x)}{1-\sin^2(x)}-\cos(x)\right)dx\\
=-\text{artanh}(\sin(x))-\sin(x)+C$$
and finally,
$$f(x)=\int\frac{-\text{artanh}(\sin(x))-\sin(x)+C}{\sin^2(x)}dx,$$ which can be solved analytically.
A: Note that $D^2+I=(D+i)(D-i)$ and, using integrating factors, we get
$$
(D+i)f(x)=e^{-ix}D\left(e^{ix}f(x)\right)
$$
and
$$
(D-i)f(x)=e^{ix}D\left(e^{-ix}f(x)\right)
$$
To invert the $D+i$ operator, first multiply by $e^{ix}$ and integrate:
$$
\begin{align}
\int e^{ix}\tan(x)\,\mathrm{d}x
&=\int\sin(x)\,\mathrm{d}x+i\int\frac{\sin^2(x)}{\cos(x)}\,\mathrm{d}x\\
&=-\cos(x)-i\sin(x)+i\int\sec(x)\,\mathrm{d}x\\[3pt]
&=-e^{ix}+i\log(\tan(x)+\sec(x))+c_1
\end{align}
$$
Finally, multiply by $e^{-ix}$ to get
$$
(D-i)f(x)=-1+ie^{-ix}\log(\tan(x)+\sec(x))+c_1e^{-ix}
$$
To invert the $D-i$ operator, first multiply by $e^{-ix}$ and integrate:
$$
\begin{align}
&\int e^{-ix}\left(-1+ie^{-ix}\log(\tan(x)+\sec(x))+c_1e^{-ix}\right)\mathrm{d}x\\
&=-ie^{-ix}+\frac{ic_1}2e^{-2ix}+i\int e^{-2ix}\log(\tan(x)+\sec(x))\,\mathrm{d}x\\
&=-ie^{-ix}+\frac{ic_1}2e^{-2ix}+\int(\sin(2x)+i\cos(2x))\log(\tan(x)+\sec(x))\,\mathrm{d}x\\
&=-ie^{-ix}+\frac{ic_1}2e^{-2ix}\\
&-\frac{1+\cos(2x)}2\log(\tan(x)+\sec(x))+\sin(x)\\
&+i\cos(x)+\frac i2\sin(2x)\log(\tan(x)+\sec(x))+c_2\\
&=\frac{ic_1}2e^{-2ix}-\frac{1+e^{-2ix}}2\log(\tan(x)+\sec(x))+c_2\\
\end{align}
$$
Finally, multiply by $e^{ix}$ to get
$$
\begin{align}
f(x)
&=\frac{ic_1}2e^{-ix}+c_2e^{ix}-\cos(x)\log(\tan(x)+\sec(x))\\
&=C_1\cos(x)+C_2\sin(x)-\cos(x)\log(\tan(x)+\sec(x))
\end{align}
$$
