Solving $y'(x)-2xy(x)=2x$ by using power series I have a first order differential equation:
$y'(x)-2xy(x)=2x$
I want to construct a function that satisfies this equation by using power series. 
General approach:
$y(x)=\sum_0^\infty a_nx^n$
Differentiate once:
$y'(x)=\sum_1^\infty a_nnx^{n-1}$
Now I plug in the series into my diff. equation:
$\sum_1^\infty a_nnx^{n-1}-2x\sum_0^\infty a_nx^n=2x$
$\iff \sum_0^\infty a_{n+1}(n+1)x^n-2x\sum_0^\infty a_nx^n=2x$
$\iff \sum_0^\infty [a_{n+1}(n+1)x^n-2xa_nx^n]=2x$
$\iff \sum_0^\infty [a_{n+1}(n+1)-2xa_n]x^n=2x $ 
Now I can equate the coefficients:
$a_{n+1}(n+1)-2xa_n=2x$
I am stuck here. I don't really understand why equating the coefficients works in the first place. Whats the idea behind doing this. I don't want to blindly follow some rules so maybe someone can explain it to me. Do I just solve for $a_{n+1}$ now?
Thanks in advance
Edit:
Additional calculation in response to LutzL:
$\sum_1^\infty a_nnx^{n-1}-\sum_0^\infty 2a_nx^{n+1}=2x$
$\iff \sum_0^\infty a_{n+1}(n+1)x^n-\sum_1^\infty 2a_{n-1}x^n=2x$
$\iff \sum_1^\infty a_{n+1}(n+1)x^n+a_1-\sum_1^\infty 2a_{n-1}x^n=2x$
$\iff \sum_1^\infty [a_{n+1}(n+1)-2a_{n-1}]x^n=2x-a_1$
So how do I deal with the x on the other side now? Can I just equate the coefficients like this:
$a_{n+1}(n+1)-2a_{n-1}=2x-a_1$?

it may be easier to see what is going on if you $\bf don't $ use the sigma notation for the sums. here is how finding solution by series works. you assume the solution is of the form $$y = a_0 + a_1x + a_2 x^2 + a_3x^3 +\cdots\\y' = a_1 + 2a_2 x + 3a_3x^2 +\cdots $$ and sub in the differential equation $y' - 2xy = 2x.$  that gives 
$$a_1 + 2a_2 x + 3a_3x^2 +\cdots -2x\left(a_0 + a_1x + a_2 x^2 + a_3x^3 +\cdots\right) = 2x \to \\
a_1 + (2a_2 - 2a_0)x + (3a_3 - 2a_1)x^2 + (4a_4-2a_2)x^3+ \cdots = 0 + 2x + 0x^2 + 0x^3 + \cdots  \tag 1$$
we make $(1)$ hold true by picking the right values for the coefficients $a_0, a_1, a_2, \cdots$
equating the constant term, we find $$\begin{align}
1:\,a_1 &= 0\\
x:\,2a_2 - 2a_0 &= 2 \to a_2 = 1 +  a_0\\
x^2:\,3a_3 - 2a_1 &= 0 \to a_3 = 0\\
x^3:\, 4a_4 - 2a_2 &= 0 \to a_4 = \frac12a_2 = \frac12 (1+a_0)\\
x^4:\,5a_5 - 2a_3 &= 0\to a_5 = 0 \\
x^5:\, 6a_6 - 2a_4 &\to a_6 = \frac13a_2 = \frac1{3!}(1+a_0)\\
\vdots\\
a_{2n} &=\frac 1{n!}(1+a_0), a_{2n+1} = 0.
\end{align}$$
now collecting all these together, we have 
$$\begin{align}y &= a_0 + \left(1 + a_0\right)x^2 + \frac 1{2!}\left(1 + a_0\ \right)x^4 +\cdots\\
&=x^2 + \frac 1{2!} x^4 + \cdots + a_0\left(1 +  x^2 + \frac1{2!}x^4 + \frac1{3!} x^6 + \cdots\right)\\
&=e^{x^2}-1 + a_0e^{x^2}\end{align}$$
in particular, you see that if we set $a_0 = -1$ we find that $y = -1$ is a particular solution.
therefore the general solution is $$y = e^{x^2}-1 + a_0e^{x^2} $$ where $a_0$ is arbitrary.
