There are two ways to do this:
1) Find an integrating factor. That is, find some function u(x) so that multiplying the equation by u(x) makes the left side an "exact differential"- so that . Using the product rule on the right side of that, so our requirement on u(x) becomes . That means we must have or , a separable equation for u. It "separates" as which integrates to . Taking exponentials of both sides, . We don't need the general solution so take C'= 1, .
integrating the left sides just gives while we can integrate the right side using "integration by parts": Let u= x, so that du= dx and . . So and
2) Separate into "homogeneous" and "non-homogeneous" parts. That is, first find the general solution to the "homogeneous" part, . That is the same as which separates to . Integrating both sides, ln(y)= -x+ C so where .
Now try to find a "specific", single, solution to . Since we are only trying to find a single solution rather than the general solution we can try "guessing". (educated guessing, of course!) Since the right hand side of the equation is "x", try y= Ax+ B. Then and the equation becomes A+ Ax+ B= x. Since that must be true for all x, taking x= 0, we get A+ B= 0 or B= -A. Replacing B by -A gives Ax= x and, taking x= 1, A= 1 so B= -1. y(x)= x- 1 satisfies the differential equation
Finally, we add the general solution to the homogenous equation to the specific solution to the non-homogeneous equation to get the general solution to the entire equation: as before.
The second method is easier but requires more theory.