to apply fredholm alternative, which says that for an adjoint(symmetric) operator
$L$, either $Lu = f$ has a solution or $<f,v> = 1$ for all solutions $v$ of the homogeneous problem. in your case, $k cos(x)$ solves the homogeneous problem and $k \int_{-\pi}^{\pi} \cos x\cos x dx = 1$ for appropriate constant $k.$ this shows then that your problem is not solvable.
of course, you could just multiply the equation by $\cos x$ and integrate from $-\pi$ to $\pi$ and use integration by parts to obtain $0 = 1.$ this is what fredholm alternative really is.
Let me change your notation and put $y_h(x)$ as the solution you have obtained. Then:
$$y(x) = c_1 y_1(x) + c_2 y_2(x) + y_p(x),$$
where $y_p(x)$ is the particular solution of your ode. Then make use of variation of parameters and try solutions $y(x) = C(x) y_1(x)$ (for example; you could have chosen $y = C y_2$). Substitute back in the ode and you will have:
$$x^2 (C''y_1 + 2 C' y_1' + C y_1'') - 2 C y_1 = C'' x^2 + C'(2y_1' x^2/y_1) + C(x^2 y''_1 - 2 y_1) =x^3 e^x,$$
the coefficient in $C$ must vanish since $y_1$ is a solution of the homogenous part of the equation. Simplify a bit and obtain a "false" second order differential equation for $C(x)$:
$$ C'' + C' 2y'_1/y_1 = x e^x/y_1,$$
which can be solved in terms of an integrating factor, $u = e^{\int 2y'_1/y_1 \,dx} = y_1^2$, as follows:
$$\frac{d}{dx}\left( C' u\right) = u x e^x/y_1 = y_1 x e^x \Leftrightarrow C' = \frac{1}{y_1^2} \int y_1 x e^x \, dx + \frac{A}{y_1^2},$$
and hence the solution for $C$:
$$C = B + A \int\frac{dx}{y_1^2} + \int\left(\frac{1}{y_1^2} \int y_1 x e^x \, dx\right) \, dx,$$
where $A$ and $B$ are constants of integration. This readily leads you to the solution, $y(x) = C(x) y_1$:
$$y(x) =\frac{A x^2}{3}+\frac{B}{x}+\frac{2 e^x}{x}+e^x( x -2 ),$$
where you can make $c_1 = \frac{A}{3}$ (and $c_2 = B$).
I hope this may be useful to you.
Cheers!
Best Answer
The equation has solutions of the form $x^r$ if $r$ is a solution of the quadratic equation $$ a\,r\,(r-1)+b\,r+c=0. $$ If one of its roots is non negative, there will be solutions defined on $(-\infty,\infty)$. For instance, the general solution of $$ x^2\,y''-2\,x\,y'+2\,y=0 $$ is $$ y=C_1\,x+C_2\,x^2. $$