Compute partial derivatives of $\int_0^1|f-p|^2dx $ Given $p(x)=c_0+c_1x+\cdots+c_{n-1}x^{n-1}$, for $x\in[0,1]$. Consider minimize $$E(c_0,\cdots,c_{n-1})=\|f-p\|_2^2=\int_0^1|f(x)-p(x)|^2dx  $$
How can I get the partial derivatives $\partial E(c_0,\cdots,c_{n-1})/\partial c_k$ and how to write $$\frac{\partial E}{\partial c_k}=0$$ as a system $M\mathbf{c}=\mathbf{b}$?
My attempt: below as solution...
 A: $$ \frac{\partial E}{\partial c_k} = \frac{\displaystyle\partial\int_0^1\left( f(x)-\sum_{j=0}^{n-1}c_j x^j\right)^2 dx }{\partial c_k }=\int_0^1\frac{\partial }{\partial c_k}\left( f(x)-\sum_{j=0}^{n-1}c_j x^j\right)^2 dx $$
Applying the chain rule:
$$ \int_0^1\left[2\cdot\frac{\partial }{\partial c_k}\left( f(x)-\sum_{j=0}^{n-1}c_j x^j\right)\right] \left( f(x)-\sum_{j=0}^{n-1}c_j x^j\right) dx = \int_0^1 -2x^k \left( f(x)-\sum_{j=0}^{n-1}c_j x^j\right) dx  $$
$\displaystyle \frac{\partial E}{\partial c_k}=0$, is the same as
$$\sum_{j=0}^{n-1}c_j \int_0^1 x^{j+k}dx  =\int_0^1 x^kf(x)dx \Longrightarrow \sum_{j=0}^{n-1}c_j \cdot \frac{1}{j+k+1}(1-0)=\int_0^1 x^k f(x)dx $$
Let $$ \mathbf{c}= \left(\begin{array}{c}
c_0\\
\vdots\\
c_{n-1}
\end{array} \right), \ \ b_k= \int_0^1 x^k f(x)dx \ \ \mathrm{y}\ \ \mathbf{m}_k=\left(\frac{1}{k+1},\cdots,\frac{1}{k+n} \right)$$ then $\displaystyle \frac{\partial E}{\partial c_k}=0$ is the same as $\mathbf{m}_k\mathbf{c}=b_k$, for $k=0,\cdots,n-1$ we can rewrite the $n$ equations as the system $\mathbf{M}\mathbf{c}=\mathbf{b}$
$$\underbrace{\left( \begin{array}{ccc}
\displaystyle \frac{1}{0+1} & \cdots & \displaystyle \frac{1}{0+n} \\
\vdots & \ddots & \vdots\\
\displaystyle \frac{1}{n-1+1}&\cdots& \displaystyle\frac{1}{n-1+n} 
\end{array}\right)}_{\mathbf{M}} \underbrace{\left(\begin{array}{c}
c_0\\
\vdots\\
c_{n-1}
\end{array} \right)}_{\mathbf{c}}= \underbrace{\left(\begin{array}{c}
\displaystyle\int_0^1 x^0 f(x)dx\\
\vdots\\
\displaystyle\int_0^1 x^{n-1}f(x)dx
\end{array} \right)}_{\mathbf{b}}$$
