For $x_1,..,x_n \in \mathbb{R}$, what is the value of $\mu$ that minimizes $\sum_{i = 1}^{n}|x_i-\mu|$? For $x_1,..,x_n \in \mathbb{R}$, what is the value of $\mu$ that minimizes $\sum_{i = 1}^{n}|x_i-\mu|$? What about $\sum_{i = 1}^{n} w_i |x_i-\mu|$ for $w_i \geq 0$?
I'm pretty sure in both cases the answer is the average of the $x_i$, and when you introduce the weights it's just the weighted average. 
I'm not sure how to prove this though, and would appreciate any help.
 A: If you order them $x_1 < x_2 < ... < x_n$, then if $x_i \leq \mu \leq x_{i+1}$ you get
$$\sum_{k = 1}^n |x_k - \mu| = \sum_{k \leq i} (\mu - x_k) + \sum_{k > i} (x_k - \mu)$$
$$= (2i - n)\mu + \sum_{k > i} x_k - \sum_{k \leq i} x_k$$
If $x < x_1$ the same formula holds if you take $i = 0$, and if $x > x_n$ the same formula holds taking $i = n$.
So if $i < {n \over 2}$ this decreases in $\mu$, if $i > {n \over 2}$ this increases in $\mu$, and if $i = {n \over 2}$ this is constant in $\mu$. Hence the minimum is achieved at $x_{n + 1 \over 2}$ if $n$ is odd, and for any $\mu$ between $x_{n \over 2}$ and $x_{{n\over 2} + 1}$ if $n$ is even.
A: Hint: It will be helpful to draw the graph of $f(\mu):=\sum_{i=1}^n|x_i-\mu|$. Let's suppose the $x_i$ are distinct, and labelled in increasing order: $x_1<x_2<\cdots<x_n$. Then $f$ is convex, and the graph of $f$ is piecewise linear, with slopes of the "pieces" ranging (in order) through $\{-n,-n+2,\ldots,n-2,n\}$. As we move from left to right in the graph of $f$, each time $\mu$ passes one of the $x_i$, the slope of the graph of $f$ jumps by $+2$. It should now be easy to find the minima of $f$. (Unique only if $n$ is odd.)  
The weighted case is similar, if slightly more complicated.
