Solving first order differential equation with power series

So, I was told solve the equation $y' - y = x^2$ using power series. Normal methods tell me that the solution is $y = c_{0}e^{x}-x^{2}-2x-2$, and this can be verified by plugging it back in. However, I am stuck on trying to solve this with power series.

We assume $y = \Sigma_{n=0}^{\infty}a_{n}x^{n}$. Thus, $y' = \Sigma_{n=0}^{\infty}a_{n+1}(n+1)x^{n}$. I plug these into the original equation.

$$\Sigma_{n=0}^{\infty}a_{n+1}(n+1)x^{n}-\Sigma_{n=0}^{\infty}a_{n}x^{n}=x^{2} \\ a_{1}x^{0}+2a_{2}x^{1}+3a_{3}x^{2}+4a_{4}x^{3}+\dots-a_{0}x^{0}-a_{1}x^{1}-a_{2}x^{2}-a_{3}x^{3}-\dots = x^{2}$$ By equating powers of $x$, I find the following relations $$a_{1}-a_{0}=0 \\ 2a_{2}-a_{1}=0 \\ 3a_{3}-a_{2}=1 \\ 4a_{4}-a_{3}=0 \\ \vdots \\ na_{n}-a_{n-1}=0$$ So, I write the coefficients as $$a_{1}=a_{0}\\ a_{2}=\frac{a_{1}}{2}=\frac{a_{0}}{2}\\ a_{3}=\frac{1}{3}+\frac{a_{2}}{3}=\frac{a_{0}}{6}+\frac{1}{3}\\ a_{4}=\frac{a_{0}}{24}+\frac{1}{12}\\ \vdots\\ a_{n}=\frac{a_{n}}{n!}+\frac{2}{n!}$$ Combining these to form $y$, I get $$y=\Sigma_{n=0}^{\infty}\frac{a_{0}}{n!}x^{n}+\Sigma_{n=3}^{\infty}\frac{2}{n!}x^{n}$$ The first bit gives me $a_{0}e^{x}$ as expected, but I don't see how to extract $-x-2x-2$ from the second half.

Is there something wrong in my approach that lead to an incorrect answer, or am I missing something in the manipulation of power series?

• Your answer is correct. Notice $$\sum_{n=3}^\infty\frac2{n!}x^n=\sum_{n=0}^\infty\frac2{n!}x^n-\sum_{n=0}^2\frac2{n!}x^n=2e^x-x^2-2x-2$$ – Kemono Chen May 27 '18 at 5:00

$$y=\sum_{n=0}^{\infty}\frac{a_{0}}{n!}x^{n}+\sum_{n=3}^{\infty}\frac{2}{n!}x^{n}$$ Transform the last part as an exponential and it will be aborbed by the first series excet for the three first terms $$\sum_{n=3}^{\infty}\frac{2}{n!}x^{n}=\sum_{n=0}^{\infty}\frac{2}{n!}x^{n} -2-2x-x^2$$ Therefore $$y=\sum_{n=0}^{\infty}\frac{a_{0}}{n!}x^{n}+\sum_{n=0}^{\infty}\frac{2}{n!}x^{n} -2-2x-x^2$$ $$y=\sum_{n=0}^{\infty}\frac{(a_{0}+2)}{n!}x^{n} -2-2x-x^2$$ $a_0$ is just a constant substitute $K=a_0+2$ $$y=\sum_{n=0}^{\infty}\frac{K}{n!}x^{n} -2-2x-x^2$$ $$y=K\sum_{n=0}^{\infty}\frac{x^{n}}{n!} -2-2x-x^2$$ Since $e^x=\sum_{n=0}^{\infty}\frac{x^{n}}{n!}$ $$y={K}e^x -2-2x-x^2$$