Part of a homework question asks us to find the partial derivative $\frac{\partial C}{\partial x_i}$ of $$C(x)=(Ax−r)^2 =\sum_{i=1}^n\left(\sum_{j=1}^m A_{ij}x_j - r_i\right)^2$$ where $A$ is an $n\times m$ matrix, $x_j$ is a vector with $m$ entries and $r$ is a vector with $n$ entries.
The method I have tried is to fix $k$, and then using the chain rule $$ \frac{\partial}{\partial x_k}\left\{\sum_{i=1}^n\left(\sum_{j=1}^m A_{ij}x_j - r_i\right)^2\right\} = 2\sum_{i=1}^nA_{ik} \left\{ \sum_{j=1}^m (A_{ij}x_j) - r_i \right\} $$
since for $j\neq k$ the derivative of $A_{ij}x_j$ in the inner sum is zero. Is it ok to just use the chain rule for the derivative of a sum? How should I be going about this?
Your computation is correct. Nicely done.
Note: I believe there is a minor error in your statement of the reasoning: you say "since for $i\neq k$...", but this should be "since for $\boxed{j}\neq k$..." because it is the inner sum, indexed by $j$, that is affected. Otherwise, all good.