<s>[INST] Help with a Differential Equation / Variation of Parameters - Wrong Answer Problem:
Solve the following differential equation.
\begin{eqnarray*}
y'' + y &=& \cot x \\
\end{eqnarray*}
Answer:
The solution I seek is $y = y_c + y_p$ where $y_c$ is the solution to
the corresponding homogeneous differential equation. To find $y_c$ I setup
the following characteristic equation.
\begin{eqnarray*}
m^2 + 1 &=& 0 \\
m^2 &=& -1 \\
m &=& \pm i \\
y_c &=& c_1 \sin x + c_2 \cos x \\
\end{eqnarray*}
Now to find $y_p$, I use the technique of variation of parameters.
\begin{eqnarray*}
y_p &=& v_1(x) \sin x + v_2(x) \cos x \\
y'_p &=& v_1(x) \cos x - v_2(x) \sin x + v'_1(x) \sin x + v'_2(x) \cos x \\
\text{ Now, I impose the condition } &&
    v'_1(x) \sin x + v'_2(x) \cos x = 0 \\
y'_p &=& v_1(x) \cos x - v_2(x) \sin x \\
y''_p &=& -v_1(x) \sin x - v_2(x) \cos x
    + v_1'(x) \cos x - v_2'(x) \sin x \\
\end{eqnarray*}
\begin{eqnarray*}
y'' + y &=& -v_1(x) \sin x - v_2(x) \cos x + v_1'(x) \cos x - v_2'(x) \sin x
    + v_1(x) \sin x + v_2(x) \cos x \\
y'' + y &=& v_1'(x) \cos x - v_2'(x) \sin x = \cot x \\
\end{eqnarray*}
Now, I have a system of two linear equations. I apply Cramer's rule to solve
it.
\begin{eqnarray*}
v'_1(x) \sin x + v'_2(x) \cos x &=& 0 \\
v_1'(x) \cos x - v_2'(x) \sin x &=& \cot x \\
\begin{vmatrix}
\sin x & \cos x \\
\cos x & - \sin x \\
\end{vmatrix} &=& - { \sin ^ 2 x } - { \cos ^ 2 x } = -1 \\
\begin{vmatrix}
0 & \cos x \\
\cot x & - \sin x \\
\end{vmatrix} &=& - \cot x ( \cos x ) = -\frac{\cos ^ 2 x}{\sin x} \\
v'_1(x) &=& \frac{ -\frac{\cos ^ 2 x}{\sin x} } { -1 } =
    \frac{\cos ^ 2 x}{\sin x} \\
%
v_1(x) &=&
    \cos(x) + \ln ( \sin( \frac{x}{2} ) ) - \ln ( \cos ( \frac{x}{2} ) ) \\
%
\frac{\cos ^ 2 x}{\sin x}(\sin x) + v'_2(x) \cos x &=& 0 \\
\cos ^2 x + v'_2(x) \cos x &=& 0 \\
\cos x + v'_2(x) &=& 0 \\
v'_2(x) &=& - \cos x \\
v_2(x) &=& - \sin x \\
\end{eqnarray*}
Hence, the solution is
\begin{eqnarray*}
y &=& c_1 \sin x + c_2 \cos x +
    ( \cos(x) + \ln ( \sin( \frac{x}{2} ) ) - \ln ( \cos ( \frac{x}{2} ) ) )
        (\sin x) + - \sin x (\cos x) \\
y &=& c_1 \sin x + c_2 \cos x +
    ( \ln ( \sin( \frac{x}{2} ) ) - \ln ( \cos ( \frac{x}{2} ) ) ) (\sin x) \\
\end{eqnarray*}
However, the book gets the following answer and I have reason to believe the
book is right.
\begin{eqnarray*}
y &=& c_1 \sin x + c_2 \cos x + (\sin x)( \ln | \csc x - \cot x | ) \\
\end{eqnarray*}
I am hoping that somebody can tell me what I did wrong.
 [/INST] You have the correct answer. (You merely forgot to account for the absolute values when integrating to get the logarithm function.) Combine the two logarithms in your answer, and use the trigonometric identity:
$$\tan(x/2)=\csc(x)-\cot(x)$$
</s>