What is the solution to the differential equation $\frac {dy}{dx} + xy = x$, when $y(0)=-6$? I know about implicit differentiation and integrals, but how do I solve this type of equations?
 A: Multiply the equation with $e^{x^2/2}$:
$$e^{x^2/2} y' + x e^{x^2/2} y = x e^{x^2/2}.$$
Now the left hand side can be written as a derivative:
$$e^{x^2/2} y' + x e^{x^2/2} y = (e^{x^2/2} y)'.$$
Thus we have,
$$(e^{x^2/2} y)' = x e^{x^2/2}.$$
We can now take the antiderivative of this:
$$e^{x^2/2} y = e^{x^2/2} + C,$$
where $C$ is some constant.
Then we multiply the equation with $e^{-x^2/2}$:
$$y = 1 + C e^{-x^2/2}.$$
Finally we use the condition $y(0) = -6$:
$$-6 = y(0) = 1 + C,$$
i.e.
$$C = -7.$$
Thus we arrive at the solution,
$$y(x) = 1 - 7 e^{-x^2/2}.$$
A: As said by Minus One-Twelfth any differential equation of the form
$$y'+p(x)y=q(x)$$
can be solved by multiplying through by an 'integrating factor' given by
$$IF=\exp{\left(\int p(x) dx\right)}$$
which gives the new equation
$$\exp{\left(\int p(x) dx\right)}y'+p(x)\exp{\left(\int p(x) dx\right)}y=q(x)\exp{\left(\int p(x) dx\right)}$$
$$\frac{\mathrm{d}}{\mathrm{d}x}\left(\exp{\left(\int p(x) dx\right)}y\right)=q(x)\exp{\left(\int p(x) dx\right)}$$
$$\therefore y=\exp{\left(-\int p(x) dx\right)}\int q(x)\exp{\left(\int p(x) dx\right)}dx$$
