Solution (source code)

= Solution

The <homogeneous linear differential equation> has solutions $\cos x$ and $\sin x$. Since the forcing is already a homogeneous solution, seek a <particular solution> proportional to $x\cos x$. Direct <differentiation> gives
$$
\left(-\tfrac12x\cos x\right)''-\tfrac12x\cos x=\sin x.
$$
Thus the general solution of the <linear ordinary differential equation> is
$$
y=A\cos x+B\sin x-\tfrac12x\cos x.
$$
The first <initial condition> gives $A=0$. Also
$$
y'=-A\sin x+B\cos x-\tfrac12\cos x+\tfrac12x\sin x,
$$
so the second <initial condition> gives $B-\tfrac12=-\tfrac12$, hence $B=0$. Therefore
$$
\boxed{y(x)=-\tfrac12x\cos x.}
$$