Solving $y'' - \frac{1}{x} y' + (1+\frac{\cot x}{x}) y = 0$ by rank reduction With the substitution $$y(x) = \sin x \int u(x) \, dx\tag{*}$$ I managed to get to$$u'(x) = \left(\frac{1}{x}-2\cot x\right)u(x)$$ Solving which gave me $$u(x) = C_1 \frac{x}{\sin^2 x}$$
Inserting that back into $(*)$ $$y(x) = (\sin x) C_1\int \frac{x}{\sin^2 x} \, dx = (\sin x) C_1 \left(\log(\sin x) - \frac{x}{\cot x} + C_2\right)$$
Which doesn't seem to be the correct solution(s). I don't know where I went wrong though.
 A: We have a theorem:

There exists a fundamental set of solutions for a homogenous linear 2th-differential equation $a_2(x)y''+a_1(x)y'+a_0(x)y=0$ on an interval $I$.

You have a second order homogenous differential equation which is linear as well. This is essential to have an independent set of solutions $\{y_1(x),y_2(x)\}$ for further aim. As you noted, there is a method in which we can construct a second solution from a known solution such that the latter set is a fundamental set (called reducing the order). It can be proved that if $y_1(x)$ is a known solution then the second one satisfying the theorem is $$y_2(x)=y_1(x)\int\frac{e^{-\int\frac{a_1(x)}{a_2(x)}dx}}{y_1^2(x)}dx$$
So in your equation we have $$y_2=\sin(x)\int\frac{e^{\int\frac{1}{x}dx}}{\sin^2(x)}dx=\sin(x)\int\frac{x}{\sin^2(x)}dx$$ $$y_2=\sin(x)(-x\cot(x)+\ln(\sin(x)))=-x\cos(x)+\sin(x)\ln(\sin(x))$$ Now, your general solution is as $y(x)=C_1y_1(x)+C_2y_2(x)$.
A: $$y(x) = \sin(x) \int_0^x u(t) dt \implies y'(x) = \cos(x) \int_0^x u(t) dt + \sin(x) u(x)$$
$$y''(x) = -\sin(x) \int_0^x u(t) dt + \cos(x) u(x) + \cos(x) u(x) + \sin(x) u'(x)\\ = \sin(x) \left( u'(x)-\int_0^x u(t) dt\right) +2 \cos(x) u(x)$$
Hence,
$$y''(x) + y(x) = \sin(x) u'(x) +2 \cos(x) u(x)$$
$$-y' + \cot(x) y = -\sin(x) u(x)$$
\begin{align}
y''(x) - \dfrac{y'(x)}x + \left(1 + \dfrac{\cot(x)}x \right)y(x) & = \sin(x) u'(x)- \sin(x) \dfrac{u(x)}x +2 \cos(x) u(x)\\
& = \sin(x) \left( u'(x) - \dfrac{u(x)}x\right) +2 \cos(x) u(x)
\end{align}
Hence, we get that $$u'(x) + \left( 2 \cot(x) - \dfrac1x\right) u(x) = 0$$
Now you should be able to finish it off. Hence, we get that $u(x) = c\dfrac{x}{\sin^2(x)}$.
Hence, $$y(x) = c \sin(x) \int_0^x \dfrac{t}{\sin^2(t)} dt$$
The error is in performing the integral.
$$\int \dfrac{t}{\sin^2(t)}dt = \log(\sin(t)) - t \cot(t) + k$$
Now you should get the right solution.
