solve : $xy''+2y'+xy=1$ given that $y=\frac{\sin x}{x}$ is a solution for $xy''+2y'+xy=0$, solve $xy''+2y'+xy=1$.
My try:
$\begin{aligned}xy''+2y'+xy&=0\\y''+\frac2xy'+y&=0\\\begin{pmatrix}
\frac{\sin x}x& u\\
\frac{x\cos(x)-\sin(x)}{x^2} & u'
\end{pmatrix}&=\frac2x\\\frac{\sin x }{x}u'-\frac{x\cos(x)-\sin(x)}{x^2}u&=\frac2x\\\left(u\frac{x}{\sin x}\right)'&=\frac{2x}{\sin^2x}\\u\frac{x}{\sin x}&=2\left(-x\cot x+\log\left(\sin x\right)\right)+c\\u&=2\left(-\cos x+\frac{\sin x\log\sin x}x\right)+c\frac{\sin x}x\\\end{aligned}$.
So it we found another solution.
Now let's try to find a specific solution for :
$y''+\frac2xy'+y=\frac1x$
The undetermined coefficient method seems to be inefficient here, does anyone have an efficient solution for this.
 A: $$xy''+2y'+xy=0$$
By reduction of order method
$$y=vy_1=v \dfrac {\sin x}x$$
But your DE is simply
$$(xy)''+xy=0$$
And thats easy to solve since it's a differential equation of order two with constants coefficients.
$$\implies r^2+1=0$$
$$\implies xy=c_1\cos x +c_2 \sin x$$
$$y(x)=\dfrac 1 x (c_1\cos x +c_2 \sin x)$$
Or as suggested by @LutzLehmann in the comment, a much better way to solve the DE is to consider:
$$xy''+2y'+xy=1$$
$$(xy-1)''+(xy-1)=0$$
$$xy-1=c_1\cos x +c_2 \sin x$$
$$y(x)=\dfrac 1x(c_1\cos x +c_2 \sin x+1)$$

Edit1
With Wronskian method
Your Wronskian is not correct $W \ne \dfrac 2x$:
$$W= \exp \int - \dfrac 2 x dx=\dfrac 1 {x^2}$$
So that
$$y_1y'_2-y'_1y_2=\dfrac 1  {x^2}$$
$$\left (\dfrac {y_2}{y_1} \right)'=\dfrac 1 {x^2}\dfrac {x^2}{\sin ^2 x}=\dfrac 1 {\sin^2 x}$$
$$y_2 = \dfrac {\sin x}{x} \int \dfrac {dx} {\sin^2 x}$$
$$y_2 = -\dfrac {\sin x \cot x}{x}$$
$$y_2 =- \dfrac {\cos x}{x}$$
The solution to the homogeneous equation is:
$$y(x)=c_1y_1+c_2y_2=\dfrac 1 x (c_1 \sin x+ c_2 \cos x)$$
A: With the change of variables $v = xy$ we get the following differential equation
$$v''+v = 1$$
which has a general solution of
$$v = A\sin x + B\cos x + 1$$
which means the general solution for $y$ is given by
$$y = A\frac{\sin x}{x}+B\frac{\cos x}{x}+\frac{1}{x}$$
If you want the solution to be extendable to a smooth function at $0$, this forces $B=-1$
A: $$y''-\frac{2}{x}y'+y=0~~~(1)$$, if $y_1=\frac{\sin x}{x}$ is a solution of (1), then the other solution $y_2(x)$ is given by
$$y_2(x)=y_1(x) \int \frac{e^{\int p(x) dx}}{y^2_1(x)}dx,~ p(x)=-2/x$$
$$\implies y_2(x)= \frac{\sin x}{x} \int \frac{1}{x^2}\frac{x^2}{\sin ^2 x} dx$$
One may ignor the multiplicative $-$ sign for $y_2(x)$.
$$\implies y_2(x)=\frac{\sin x}{x} \int \csc^2 x dx=-\frac{\cos x}{x}.$$
For solving the inhomogeneous equation $$Y''-\frac{2}{x}Y'+Y=\frac{1}{x}~~~(2)$$
the method of variation of parameter can be used which requires $y_1(x), y_2(x)$, the solution of (2) is given by $$Y(x)=C_1(x) y_1(x)+ C_2(x) y_2(x)~~~(3)$$
where $$C_1(x)=-\int \frac{y_2(x)/x}{W(x)} dx+D_1= \int \cos x dx+D_1=\sin x +D_1.$$
The Wronskian $W(x)$ of $y_1,y_1$ is $-1/x^2$.
Similarly, we have $$C_2=\int \frac{y_1(x)/x}{W(x)} dx+D_2=-\int \sin x dx+D_2=\cos x +D_2.$$
Inserting , $y_1(x), y_2(x). C_1(x), C_2(x)$ in (3), we get
$$Y(x)=\frac{1}{x}[D_1 \sin x+ D_2 \cos x]+\frac{1}{x}[\sin^2 x+ \cos^2 x].$$
$$\implies Y(x)=\frac{1}{x}[D_1 \sin x+ D_2 \cos x]+\frac{1}{x},$$
which is the solution of the reqyured ODE (2).
For the method of Variation of Parameters see:
https://en.wikipedia.org/wiki/Variation_of_parameters
