How to correctly differentiate sum term Given a function $f_i (x_1,\dots, x_N)$ that is summed over, how do I find the correct partial derivative? 
\begin{equation}
f_i = \sum _{j=1}^Nc_{ij}x_ix_j 
\end{equation}
Then, 
\begin{equation}
\frac{\partial}{\partial x_k}f_i = \frac{\partial}{\partial x_k}\sum _{j=1}^Nc_{ij}x_ix_j 
\end{equation}
I assume the derivative is distributive. 
\begin{equation}
\frac{\partial}{\partial x_k}f_i =\sum _{j=1}^N \frac{\partial}{\partial x_k} c_{ij}x_ix_j
\end{equation}
I then have,
\begin{equation}
\frac{\partial}{\partial x_k}f_i =\sum _{j=1}^N c_{ik}x_i \delta_{jk} \qquad   \qquad \qquad   * 
\end{equation}
But I can also write,
\begin{equation}
\frac{\partial}{\partial x_k}f_i=  2c_{kk}x_k + \sum _{j\neq k}^N c_{ij}x_j\qquad   \qquad \qquad   $
\end{equation} 
So is * or $ the correct result? 
 A: The correct answer depends on the fact whether $k=i$ or $k\ne i$. It is convenient to separate these two cases.

$(k\ne i)$: We obtain
  \begin{align*}
\frac{\partial }{\partial x_k}f_i&=\frac{\partial }{\partial x_k}\sum_{j=1}^Nc_{ij}x_ix_j\\
&=\frac{\partial }{\partial x_k}\sum_{{j=1}\atop{j\ne k}}^{N}c_{ij}x_ix_j+\frac{\partial }{\partial x_k}c_{ik}x_ix_k\\
&=0+c_{ik}x_i\\
&=c_{ik}x_i
\end{align*}
$(k=i)$: We obtain
  \begin{align*}
\frac{\partial }{\partial x_k}f_k&=\frac{\partial }{\partial x_k}\sum_{j=1}^Nc_{kj}x_kx_j\\
&=\frac{\partial }{\partial x_k}\sum_{{j=1}\atop{j\ne k}}^{N}c_{kj}x_kx_j+\frac{\partial }{\partial x_k}c_{kk}x_k^2\\
&=\sum_{{j=1}\atop{j\ne k}}^{N}c_{kj}x_j+2c_{kk}x_k
\end{align*}

A: $\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
\partiald{f_{i}}{x_{k}} & =
\sum _{j = 1}^{N}c_{ij}
\pars{\partiald{x_{i}}{x_{k}}\,x_{j} + x_{i}\,\partiald{x_{j}}{x_{k}}} =
\sum _{j = 1}^{N}c_{ij}
\pars{\delta_{ik}\,x_{j} + x_{i}\,\delta_{jk}} =
\bbx{\ds{\delta_{ik}\sum_{j = 1}^{N}c_{ij}x_{j} + c_{ik}x_{i}}}
\end{align}
