Solving $\frac{d}{dw_i}\left\{\sum_{j=0}^M w_j^2x^j +2 \sum_{kRecently I had to perform the following differentiation for some index $i\in[0,M] \cap \mathbb{N}$
$$\frac{d}{dw_i}\left\{\sum_{j=0}^M w_j^2x^{2j} +2 w_jx^j\sum_{k<j} w_kx^k\right \}$$
With the given solution 
$$2\sum_{j=0}^M w_jx^{j+i}$$
Could someone please help me with the derivation? Because I end up summing from the i'th term in my solution
$$2\sum_{k=i}^M w_kx^{k+i}$$
By the sum rule I can distribute $\frac{d}{dw_i}$, so
$$\frac{d}{dw_i}\sum_{j=0}^M w_j^2x^{2j} +2 \frac{d}{dw_i}w_jx^j\sum_{k<j} w_kx^k$$
In the first sum $\forall w_j \neq w_i.w_j=0$, after differentiating, so the sum reduces to $2w_ix^{2i}$.
For the second sum again $\forall w_j \neq w_i.w_j=0$ so sums with a $w_j \neq w_i$ will be zero after differentiating. So the second sum reduces to $x^i\sum_{k<i}^M w_kx^k$.
Putting it all together I get
$$2w_ix^{2i} +2 x^i\sum_{k<i} w_kx^k$$
Rearranging I get the final result
$$2\sum_{k=i}^M w_kx^{k+i}$$
 A: Note that 
$$
\left(
w_j^2x^{2j}
+
2 w_jx^j\sum_{k<j} w_kx^k
\right)
=
\left\{
\begin{array}{rcl}
w_j^2x^{2j}
+
2 w_jx^j\displaystyle\sum_{k<j} w_kx^k
& 
\mbox{ if } 
&
j<i
\\
\\
w_i^2x^{2i}
+
2 w_ix^i\displaystyle\sum_{k<i} w_kx^k
& 
\mbox{ if } 
&
j=i
\\
\\
w_j^2x^{2j}
+
2 w_jx^j\displaystyle\sum_{\substack{k<j\\ k\neq i}} w_kx^k+ 2 w_jx^jw_ix^i
& 
\mbox{ if } 
&
j>i
\end{array}
\right.
$$
implies 
$$
\frac{d}{d w_i}
\left(
w_j^2x^{2j}
+
2 w_jx^j\sum_{k<j} w_kx^k
\right)
=
\left\{
\begin{array}{rcl}
0
& 
\mbox{ if } 
&
j<i
\\
\\
2w_ix^{2i}
+
2 x^i\displaystyle\sum_{k<i} w_kx^k
& 
\mbox{ if } 
&
j=i
\\
\\
2 w_jx^jx^i
& 
\mbox{ if } 
&
j>i
\end{array}
\right.
$$
Then calculate the derivative $\frac{d}{d w_i}$ of
\begin{array}{rl}
\displaystyle\sum_{\substack{0\leq j\leq M}}
\left(
w_j^2x^{2j}
+
2 w_jx^j\displaystyle\sum_{k<j} w_kx^k
\right)
=&
\displaystyle\sum_{\substack{0\leq j< i }} 
\left(
w_j^2x^{2j}
+
2 w_jx^j\displaystyle\sum_{k<j} w_kx^k
\right)
\\
&+\left(
w_i^2x^{2i}
+
2 w_ix^i\displaystyle\sum_{k<i} w_kx^k
\right)
\\
&+
\displaystyle\sum_{\substack{i< j\leq M}}
\left(
w_j^2x^{2j}
+
2 w_jx^j\displaystyle\sum_{k<j} w_kx^k
\right)
\end{array}
