Easiest way to solve $y''+y=\frac{1}{\cos x}$

I know how to solve it using Lagrange method of variation of constants, but is there easier way?

Solutions Collecting From Web of "Easiest way to solve $y''+y=\frac{1}{\cos x}$"

The solution to
$$
y”+y=0,\quad y(0)=0,\quad y'(0)=1
$$
is
$$
y(x)=\sin x
$$
Therefore, a particular solution to the problem we study is given by
$$
\begin{aligned}
y(x)&=\int_0^x \sin(x-t)\sec(t)\,dt\\
&=\int_0^x \sin x-\cos x\tan t \,dt\\
&=x\sin x+\cos x\times\ln(\cos x).
\end{aligned}
$$
The solution to the homogeneous equation is trivial, so the general solution is
$$
y(x)=A\cos x+(B+x)\sin x+\cos x\times\ln(\cos x),
$$
where $A$ and $B$ are arbitrary constants. I leave it to you to think of what happens when $\cos x\leq 0$.

Consider the differential equation $$y”+a^2y=\sec ax$$

The auxiliary equation is $m^2+a^2=0$ which gives $m=\pm ia$

Hence $$CF=c_1\cos ax+c_2\sin ax$$

$$PI=\frac{1}{D^2+a^2}\sec ax=\frac{1}{(D-ia)(D+ia)}\sec ax\\
=\frac{1}{2ia}(\frac{1}{D-ia}-\frac{1}{D+ia})\sec ax$$

Now, $$\frac{1}{D-ia}\sec ax=e^{iax}\int e^{-iax}\sec ax \mathrm dx\\
=e^{iax}\int\frac{\cos ax-i\sin ax}{\cos ax}\mathrm dx=e^{iax}(x+\frac{i}{a}\log\cos ax)$$

Replacing $i$ by $-i$ we have, $$\frac{1}{D+ia}\sec ax=e^{-iax}(x-\frac{i}{a}\log\cos ax)$$

Now Using these and simplifying we have $$PI=\frac{1}{a^2}(ax\sin ax+\cos ax\cdot\log\cos ax)$$

Hence the general Solution is:

$$y=c_1\cos ax+c_2\sin ax+\frac{1}{a^2}(ax\sin ax+\cos ax\cdot\log\cos ax)$$

Put $a=1$ in this you will get your answer in very few steps.