I am trying to solve the DE $y''+y=x^2$ using the series expansion method. First, I assume that there exists a solution
$$y=a_0+a_1 x+a_2 x^2+a_3 x^3+a_4 x^4+a_5x^5+...$$
$$\therefore y'=0+a_1 +2a_2 x+3a_3 x^2+4a_4x^3+5a_5x^4...$$
$$\therefore y''=0+0 +2a_2 +6a_3 x+12a_4x^2+20a_5x^3...$$
Substituting into the DE,
$$(2a_2 +6a_3 x+12a_4x^2+20a_5x^3+...)+(a_0+a_1 x+a_2 x^2+a_3 x^3+a_4 x^4+...)=x^2$$
and then equating coefficients of like-powers,
$$x^0\Rightarrow2a_2+a_0=0$$ $$x^1\Rightarrow6a_3+a_1=0$$ $$x^2\Rightarrow12a_4+a_2=1$$ $$x^3\Rightarrow20a_5+a_3=0$$
So then solving for the recursion relations, given that the RHS isn't $x^2$ but $0$ instead, a very simple Maclaurin series appears, giving $\sin x$ and $\cos x$. But it isn't $0$. There's a discontinuity in the pattern because a random 1 comes out from the $x^2$ term. How does one account for this? Could I simple do the term for all terms $=0$ and THEN subtracting it from the sin or cos term, then adding the proper term with the 1 for $x^2$? Maybe that's confusing... anyway could someone fill me in on the next step? Literally all the answers on here for questions like mine didn't help me. Thanks
Hint
You properly identified the solution of $y''+y=0$. May be, you could also notice that $y=x^2-2$ is a solution of the equation. So $$y=c_1\cos(x)+c_2\sin(x)+x^2-2$$ could make you happy !
Merry Xmas !