<s>[INST] How to simplify solutions for $y'' + 4y = 2 \tan x$? The original equation is $$y'' + 4y = 2 \tan x$$
What I did so far:
$$\lambda^2+4 = 0$$
$$\lambda_1 = -2i \quad \lambda_2 = 2i$$
$$y(x) = C_1\cos2x+C_2\sin2x$$

Write down the system:
$$\begin{cases} C_1'\cos2x + C_2'\sin2x = 0 \\
2C'_2\cos2 x - 2C_1'\sin2x = 2\tan x \end{cases}$$

Applying Krammer's formulas
$$\Delta = \begin{vmatrix}\cos2x & \sin2x \\ 2\cos2x  & -2\sin2x \end{vmatrix} = -2\cos4x$$
$$\Delta_2 = \begin{vmatrix} 0 & \sin2x \\ 2\tan x & -2\sin2x\end{vmatrix} = -2\tan x\sin2x = -4\sin^2x$$
$$\Delta_3 = \begin{vmatrix}\cos2x & 0 \\ 2\cos2x & 2\tan x \end{vmatrix} = -2\cos2x\tan x$$
but when I tried to find solutions I got different expressions which I do not know how to integrate, what is the best way to simplify solutions here to get better integrals?
 [/INST] There is an error in your calculation of $\Delta$.
$$ \Delta = \begin{vmatrix}\cos(2x) &\sin(2x) \\ -2\sin(2x) &2\cos(2x)\end{vmatrix} = 2\cos^2(2x)+2\sin^2(2x) = 2$$
$$ C'_1 = \frac{\Delta_2}{\Delta} = -2\sin^2 x$$
$$ C_1 = -2\int sin^2 x \; dx = \frac{1}{2}\sin(2x) -x$$  
$$ C'_2 = \frac{\Delta_3}{\Delta} = -\cos(2x)\tan (x)$$
\begin{align} 
C_2 
&= -\int \cos(2x)\tan (x) \; dx 
=-\int \frac{(2\cos^2 x -1)\sin x}{\cos x} \, dx \\ 
&= \int \frac{\sin x}{\cos x} - \int 2\cos x \sin x\, dx 
= -ln|\cos x| + \cos^2 x
\end{align}
</s>