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$?

You have to compare coefficients of like powers, there should be no variable $x$ remaining in the resulting equations. For that one has invented a technique called "index shift", that you actually correctly employed in the case of the derivative series. In the other part,
$$
x\sum_{k=0}^\infty a_kx^k=\sum_{k=0}^\infty a_kx^{k+1}=\sum_{n=1}^\infty a_{n-1}x^n
$$
And using the Kronecker delta
$$
2x=\sum_{n=0}^\infty (2\delta_{n,1})x^n
$$
where
$$
δ_{n,a}=\begin{cases}1&n=a\\0&n\ne a\end{cases}
$$
