Differential equation $y”+y=\tan(x)$

ordinary differential equations

Given the following differential equation:
\begin{align}
y''+y=\tan(x)
\end{align}

I tried this way:
\begin{align}
y_H(x)=A\cos(x)+ B\sin(x)\\ A,B\in \Re \\
y_p(x)=A(x)\cos(x)+B(x)\sin(x)
\end{align}

I continue with the Wronski method
\begin{align}
W(F)= \begin{bmatrix}
\cos(x) & \sin(x) \\
-\sin(x) & \cos(x)
\end{bmatrix}\\\\
det \ W(F) = 1 \neq 0
\end{align}

So is invertible
\begin{align}
W(F)^{-1}= \begin{bmatrix}
\cos(x) & -\sin(x)\\
\sin(x) & \cos(x)
\end{bmatrix}\\\\
\end{align}

Now since:
\begin{align}
W(F) \cdot\begin{bmatrix}
A'(x) \\ B'(x)
\end{bmatrix}= \begin{bmatrix}
0 \\ b(x)
\end{bmatrix}\\\\
\begin{bmatrix}
A'(x) \\ B'(x)
\end{bmatrix}=
\begin{bmatrix}
\cos(x) & -\sin(x) \\
\sin(x) & \cos(x)
\end{bmatrix}
\cdot
\begin{bmatrix}
0 \\ \tan(x)
\end{bmatrix}\\\\
B'(x)= \cos(x) \tan(x)=\sin(x) \\
B(x) = -\cos(x)\\\\
A'(x) = -\sin(x)\tan(x)\\
A(x) = -\int \sin(x) \tan(x) dx = \cos(x)\tan(x) – \int \frac{1}{\cos(x)} dx= \\
= \sin(x) – \frac{1}{2} \log{\frac{1+sin(x)}{1-\sin(x)}}\\\\
y_p(x)=A(x)\cos(x) + B(x)\sin(x) = \\\\
= \sin(x)\cos(x) – \frac{1}{2}\cos(x) \log{\frac{1+sin(x)}{1-\sin(x)}} +
-\cos(x)\sin(x)= \\\\ – \frac{1}{2}\cos(x) \log{\frac{1+sin(x)}{1-\sin(x)}}
\end{align}

So now the linear combination of the two solution should be
\begin{align}
y(x)= A\cos(x) + B\sin(x) – \frac{1}{2}\cos(x) \log{\frac{1+sin(x)}{1-\sin(x)}}
\end{align}

but the correct solution is
\begin{align}
y(x)= A\cos(x) +B\sin(x) + \cos(x) \log\left(\frac{\cos(\frac{x}{2})-\sin(\frac{x}{2})}{cos(\frac{x}{2})+sin(\frac{x}{2})}\right)
\end{align}

Is my solution wrong? If yes where I did the mistake?
Is my solution right? How can I get the other form? What steps I need to do?

Best Answer

Your solution is correct just note that $(\sin(x/2)\pm \cos+x/2))^2=1\pm \sin(x)$. Now use the log property that $\log(a^b)=b\log(a)$ and you are done. And if you are confused with the discrepancy of plus and minus sign before the log expression we have $\log(\frac{1}{x})=-\log(x)$

Related Question