Divide original equation through by x and rearrange:
y'-(x+2)y/x=2x+2, y'-(1+2/x)y=2x+2.
Find integrating factor: e∫-(1+2/x)dx=e-x-2ln(x)=e-xe-2ln(x)=e-x/x2. (-2ln(x)=-ln(x2)=ln(1/x2); eln(1/x²)=1/x2)
Multiply through by e-x/x2:
e-xy'/x2-(x+2)ye-x/x3=2e-x/x+2e-x/x2.
[Note that the derivative of e-x/x2 wrt x is found using the product rule:
e-x/x2=e-xx-2; let u=e-x, so du/dx=-e-x; v=x-2, so dv/dx=-2x-3=-2/x3;
d(uv)=udv/dx+vdu/dx=-2e-x/x3-e-x/x2=-(e-x/x2)(2/x+1)=-(e-x/x2)(x+2)/x=-(x+2)e-x/x3.]
e-xy'/x2-(x+2)ye-x/x3=d(e-xy/x2)/dx=2e-x/x+2e-x/x2,
e-xy/x2=2∫(e-x/x+e-x/x2)dx=2(I+J)=
where I=∫(e-x/x)dx and J=∫(e-x/x2)dx.
Let u=1/x, then du/dx=-1/x2; dv=e-xdx, then v=-e-x;
I=-e-x/x-∫(e-x/x2)dx=-e-x-J;
So I+J=-e-x/x+C1 (C1 is an arbitrary constant of integration),
e-xy/x2=-2e-x/x+2C1, y/x2=-2/x+Cex, y=-2x+Cx2ex, y'=-2+2Cxex+Cx2ex, xy'=-2x+2Cx2ex+Cx3ex; (C=2C1)
-(x+2)y=-xy-2y=2x2-Cx3ex+4x-2Cx2ex;
xy'-(x+2)y-2x2-2x=-2x+2Cx2ex+Cx3ex+2x2-Cx3ex+4x-2Cx2ex-2x2-2x=0.
The terms with the same colour cancel to leave no terms.
Therefore y=Cx2ex-2x is the general solution where C is an arbitrary constant.
ex=1+x+x2/2!+x3/3!+...+xn/n! and Cx2ex=C∑xn+2/n!-2x, where 0≤n≤∞.