There are several methods for solving first-order linear equations. Here's one of them:
Bring the equation into standard form, y'+p(x) y = q(x). Then find the function r(x)=e∫p(x)dx. This function is called an
integrating factor. When you multiply the equation by this factor, the left-hand side will become a total derivative, which is then easy to integrate.
Your equation is already in standard form:
y'+y=xe-x, with p(x)=1, q(x)=xe-x.
Then r(x)=e∫1dx=ex is an integrating factor, so multiply the equation by ex:
The left side is the derivative of exy:
so that when you integrate both sides of the equation,