Find minimum value of $(x-a_1)^2+(x-a_2)^2+...+(x-a_n)^2$ I have the function $f(x)=(x-a_1)^2+(x-a_2)^2+...+(x-a_n)^2$, where $a_1, ..., a_n \in ℝ$ and $n \in ℕ^*$, and I'm trying to prove why $f$ has its minimum  value when $x$ is the arithmetic mean of $a_1+a_2+...+a_n$.
How can I approach this?

(I had an epiphany while writing the question, but I'd like to see other possible solutions)
 A: Just another way, completing the square:
$$f(x)=\sum_{k=1}^n (x-a_k)^2 = n \left(x-\frac1n\sum_{k=1}^n a_k\right)^2 + \sum_{k=1}^na_k^2-\frac1n\left(\sum_{k=1}^na_k \right)^2$$
This may be clearer rewriting with $\overline x = \frac1n\sum_{k=1}^n a_k$, the arithmetic mean, we have
$$f(x) = n(x - \overline x)^2 + \sum_{k=1}^na_k^2-n \overline x^2$$
so it is clear $x=\overline x $ minimises $f(x)$.
A: This problem can be solved in three steps:


*

*First, we find the first derivative of $f$, which is the following: $$f'(x)=2\sum_{i=1}^n{(x-a_i)}=2nx-2\sum_{i=1}^n{a_i}$$

*Then, we calculate the extremum of $f$:
$$
f'(x)=0\Leftrightarrow
2nx-2\sum_{i=1}^n{a_i}=0\Leftrightarrow
nx=\sum_{i=1}^n{a_i}
\Leftrightarrow
x={{a_1+a_2+...+a_n}\over n}
$$

*Finally, we find the second derivative of $f$, which is the following:
$$f''(x)=2n$$
Since $f''(x)>0,\ \  ∀\ \ x ∈ ℝ$, $f$ is strictly convex in $ℝ$ and therefore the extremum we found above, which is the arithmetic mean of $a_1+a_2+...+a_n$, is a global minimum.
A: Let $x=\frac{1}{n}\sum_{i=1}^n a_i$, the arithmetic mean of $a_1,a_2,\cdots,a_n$.
Then, $S=\sum_{i=1}^n (a_i-a)^2$
$\qquad\quad=\sum_{i=1}^n((a_i-x)-(a-x))^2$
$\qquad\quad=\sum_{i=1}^n(a_i-x)^2+n(a-x)^2-2(a-x)\sum_{i=1}^n(a_i-x)$
$\qquad\quad=\sum_{i=1}^n(a_i-x)^2+n(a-x)^2$
$\qquad\quad\ge\sum_{i=1}^n(a_i-x)^2$, as $(a-x)^2\ge0$.
Equality holds iff $a=x$. Thus $S$ attains its minimum when $a=x$.
A: The given function$\ f$ is quadratic function clearly whose graph is concave upwards as coefficient of$\ x^2$ is positive. And as we know that if$\ g(x) = ax^2+bx+c$ ;$\ (a>0 )$ is a quadratic equation , then it has its minimum at$\ x = (\frac{-b}{2a})$ and the minimum value is ($\frac{-D}{4a})$ 
, where$\ D = b^2-4ac$ (the discriminant).
Here, we have the function like this (on careful observation):$$\ f(x) = x^2\sum_{i=1}^n 1 - 2x\sum_{i=1}^n a_i + \sum_{i=1}^n a_{i}^2$$
Evaluate it properly and compare with$\ g(x)$ to get$\ a,b,c$ and find the desired result .
Good Luck..
A: $$f(x)=(x-a_1)^2+(x-a_2)^2+...+(x-a_n)^2\implies$$
$$ f'(x)=2[(x-a_1)+(x-a_2)+...+(x-a_n)]$$
$$ f'(x)=0 \implies nx= a_1 +a_2 +...a_n$$ 
Thus $$x=\frac {a_1 +a_2 +...a_n}{n}$$ 
is the only critical point. 
It is easy to see that it is a minimizer of f(x).
