Minimizing a function with summation I'm looking to minimize:
$$F(m,b) = \sum_{i=1}^n (mx_i + b -y_i)^2 $$
By taking first order conditions $w.r.t$  m, I find:
$$\begin{align*} \frac{\partial F}{\partial m}= 2 \sum_{i=1}^n x_i(mx_i+b-y_i) &amp;=0 \\
\ 2m\sum_{i=1}^nx_i^2+2b\sum_{i=1}^n x_i -2\sum_{i=1}^n y_ix_i &amp;=0\\
\end{align*}$$
By dividing everything by 2 and rearranging:
$$m\sum_{i=1}^nx_i^2+b\sum_{i=1}^n x_i = \sum_{i=1}^n y_ix_i$$
Finally I find that
$$ m = \frac{\sum_{i=1}^n y_ix_i - b\sum_{i=1}^nx_i}{\sum_{i=1}^nx_i^2} $$
However, this answer seems strange to me as I am unsure about the math.
Can this be simplified further?
Yes the Math is correct. You minimize the equation wrt m to get the minimum point equation for m. Since the equation wrt to m is the form (f(m))^2 or g(f(m)) where g(x)=x^2, we use the chain rule to get 2 * (f(m)) * df/dm or dg/dm * (f(m)) * df/dm
Yes the Math is correct. You minimize the equation wrt m to get the minimum point equation for m. Since the equation wrt to m is the form (f(m))^2 or g(f(m)) where g(x)=x^2, we use the chain rule to get 2 * (f(m)) * df/dm or dg/dm * (f(m)) * df/dm