ans =
Before we go too far, we want to look at your claimed solution.
syms y(x) % tells matlab that y is an unknown function of x
ODE = x*diff(y,x)+y==-sin(x); % defines the ODE, so we can use it
yoursol(x) = -(x*sin(x)-cos(x))/x^2;
First, does your solution satisfy the initial conditions?
yoursol(pi/2)
In fact, no, it does not even satisfy your own boundary condition, so we know your claimed solution is not correct. I won't even bother to see if it "satisfies" the ODE, aince it cannot do so.
Now lets use dsolve to solve the ODE.
sol(x) = dsolve(ODE,y(pi/2) == 0)
Does this satisfy the ODE?
sol(pi/2)
simplify(subs(ODE,y,sol))
Sorry. It looks like dsolve got it right.
