<s>[INST] How to solve this ode $xy''-(1+x)y'+y=x^2$? Find the general solution of $xy''-(1+x)y'+y=x^2$ knowing that the homogeneous equation has the following solution: $e^{ax}$, where $a$ is a parameter you have to find.
I have found that $a=1$ or $a=1/x$.
 [/INST] The equation $xy''-(1+x)y'+y=x^2$ can be rewritten as $(xy''-y')+(y-xy')=x^2.$ After division by $x^2$ we have
$$
\frac{xy''-y'}{x^2} + \frac{y-xy'}{x^2} = 1,
$$
which can be rewritten as
$$
\Big( \frac{y'}{x} \Big)' - \Big( \frac{y}{x} \Big)' = 1.
$$
Taking the antiderivative gives
$$
\frac{y'}{x} - \frac{y}{x} = x + C,
$$
which after multiplication with $x$ gives
$$y' - y = x^2+ Cx.$$
Now we multiply with the integrating factor $e^{-x}$:
$$e^{-x} y' - e^{-x} y = x^2 e^{-x} + Cx e^{-x}.$$
The left hand side can be rewritten as a derivative:
$$( e^{-x} y )' = x^2 e^{-x} + Cx e^{-x}.$$
Taking the antiderivative gives
$$e^{-x} y = -(x^2+2x+2) e^{-x} - C(x+1) e^{-x} + D.$$
Thus, all solutions to the original differential equation are given by
$$y = -(x^2+2x+2) - C(x+1) + D e^x,$$
where $C$ and $D$ are two constants.
</s>