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$.
 A: 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.
A: Hint. You are correct, the homogeneous case of the given  linear ODE has $e^x$ as a solution (the parameter $a$ is supposed to be a constant real number). Note that $y=-x^2$ is a particular solution. Is there any other polynomial solution? Substitute $y(x)=Ax^2+Bx+C$ into the ODE, then
$$x(2A)-(1+x)(2Ax+B)+(Ax^2+Bx+C)=x^2$$
What may we conclude?
A: Substitute $$y(x)=(-x-1)v(x)$$ then we get
$$-x\frac{d^2v(x)}{dx^2(x+1)}+\frac{dv(x)}{dx}(x^2+1)=x^2$$
let $$\frac{dv(x)}{dx}=u(x)$$ then we get
$$\frac{du(x)}{dx}+\frac{-x^2-1)u(x)}{x(x+1)}=-\frac{x}{x+1}$$
with $$\mu(x)=e^{\int\frac{-x^2-1}{x(x+1)}dx}=\frac{e^{-x}(x+1)^2}{x}$$ we get
$$\frac{e^{-x}(x+1)^2}{x}\frac{du(x)}{dx}+\frac{d}{dx}\left(\frac{e^{-x}(x+1)^2}{x}\right)u(x)=-e^{-x}(x+1)$$ and this is
$$\int\frac{d}{dx}\left(\frac{e^{-x}(x+1)^2u(x)}{x}\right)=\int-e^{-x}(x+1)dx$$
Can you finish?
