2.90   ODE No. 90

\[ x y'(x)+y(x)-x \sin (x)=0 \] Mathematica : cpu = 0.0222962 (sec), leaf count = 24

DSolve[-(x*Sin[x]) + y[x] + x*Derivative[1][y][x] == 0,y[x],x]
 

\[\left \{\left \{y(x)\to \frac {\sin (x)-x \cos (x)}{x}+\frac {c_1}{x}\right \}\right \}\] Maple : cpu = 0.018 (sec), leaf count = 17

dsolve(x*diff(y(x),x)+y(x)-x*sin(x) = 0,y(x))
 

\[y \left (x \right ) = \frac {\sin \left (x \right )-\cos \left (x \right ) x +c_{1}}{x}\]

Hand solution

\[ xy^{\prime }+y=x\sin x \]

Linear first order, exact, separable. \(y^{\prime }+\frac {y}{x}=\sin x\), integrating factor \(\mu =e^{\int \frac {1}{x}dx}=x\), hence\begin {align*} d\left ( \mu y\right ) & =\mu \sin x\\ xy & =\int x\sin xdx+C \end {align*}

Using integration by parts. \(\int udv=uv-\int vdu\). Let \(u=x,dv=\sin x\), hence \(du=1,v=-\cos x\), therefore\begin {align*} \int x\sin xdx & =-x\cos x+\int \cos x\\ & =-x\cos x+\sin x \end {align*}

Hence\begin {align*} xy & =-x\cos x+\sin x+C\\ y & =\frac {\sin x}{x}-\cos x+\frac {C}{x} \end {align*}

Verification

restart; 
ode:=x*diff(y(x),x)+y(x)=x*sin(x); 
my_sol:=sin(x)/x-cos(x)+_C1/x; 
odetest(y(x)=my_sol,ode); 
0