why minimum of these functions happen at a special place? why minimum of these functions happen at a special place? how to use derivative to find the minimum of these functions?
$$|x-1| + |x-2| + \dots + |x-9|$$ minimum is for $x = 5$
$$|x-1| + |x-2| + \dots + |x-99|$$ minimum is for $x = 50$
$$|x-1| + |x-2| + \dots + |x-999|$$ minimum is for $x = 500$ $$ \dots$$ why it happens?
 A: Suppose that $a_1\lt a_2\lt a_3\lt \cdots\lt a_9$. Consider the function 
$$f(x)=|x-a_1|+|x-a_2|+\cdots +|x-a_9|.$$
Then $f(x)$ is the sum of the distances from $x$ to the $a_i$.
Imagine the points $a_1,a_2,\dots,a_9$ are on the $x$-axis. A tiny bug is on the $x$-axis, well to the left of $a_1$, and starts walking in the rightward direction. 
For every tiny step $s$ that she takes, the sum of her distances from the $a_i$ decreases by $9s$.  This continues until she hits $a_1$.  Now for every tiny step $s$ that she takes, her distance from each of $a_2,a_3,\dots,a_9$ decreases by $s$, and her distance from $a_1$ increases by $s$, for a total decrease of $7s$.
This continues until she hits $a_2$.  Then for every step $s$ that she takes, her distance from each of $a_3$ to $a_9$ decreases by $s$, and her distance from each of $a_1$ and $a_2$ increases by $s$, for a total decrease of $5s$.
When she hits $a_3$, for each a tiny step to the right, there is a total decrease of $3s$.  When she hits $a_4$, there is a total decrease of $s$ for each tiny step to the right. When she hits $a_5$ and takes a tiny step, there is an increase of $s$ for each tiny step to the right. And things get worse as she continues to the right. So the minimum value of $f(x)$ was reached at $x=a_5$.
Exactly the same idea shows that if we have $a_1\lt a_2\lt\cdots  \lt a_{2m-1}$, and $f(x)=|x-a_1|+\cdots+|x-a_{2m-1}|$, then $f(x)$ reaches a minimum at $x=a_m$.
Remark: The situation is only slightly different is we have an even number of points $a_1\lt a_2\lt \cdots\lt a_{2m}$. Then the minimum value of $f(x)$ is reached at all points $x$ such that $a_m\le x\le a_{m+1}$.     
To put it in other words, if we have an odd number of terms, then $f(x)$ is minimized at the (unique) median of the $a_i$. The same is true with an even number of terms, except that there are infinitely many medians.
Note that by contrast $g(x)=(x-a_1)^2+(x-a_2)^2+\cdots +(x-a_n)^2$ is minimized at the mean $\frac{a_1+a_2+\cdots+a_n}{n}$ of the $a_i$.  
A: The function $|x-3|$ measures the distance from $x$ to $3$.  The function $|x-3|+|x-4|$ adds the distance between $x$ and $3$, to the distance between $x$ and $4$.  That distance is exactly 1 for each $x$ between $3$ and $4$, and greater than $1$ if $x$ is outside the interval $[3,4]$.  The function $|x-3|+|x-4|+|x-5|$ adds the three distances between $x$ and $3,4,5$.  Because $|x-3|+|x-5|$ is constant on the entire interval $[3,5]$ (and greater outside), the minimum is determined entirely by $|x-4|$, which is minimized at $4$ and nowhere else.
Continuing in this way, $|x-1|+|x-2|+\cdots+|x-c|$ is the total distance between $x$ and each of the values $1,2,\ldots, c$.  If there are an even number of terms (i.e. $c$ is even), then there is an interval of length 1 in the middle where the function is minimized.  If there are an odd number of terms (i.e. $c$ is odd), then there is a single point, in the middle, where the function is minimized.
A: I suppose the trick is to consider the derivative for different values of $x$, for example:
if $ x < 1$, then the derivative of $|x - 1|$ equals $-1$ and this is true for all of the other terms as well, hence the derivative is $-9$.
If $x$ is between $1$ and $2$, then the first term $|x -1|$ gives a positive contribution $+1$ to the derivative and hence the derivative is now $-7$ (8 negative contributions, 1 positive contribution).
Moving on a few steps, we see that if $x$ is between $4$ and $5$, then we have $4$ terms contributing $+1$ and $5$ terms contributing $+1$, hence the derivative equals $-1$. 
If, on the other hand, $x$ is between $5$ and $6$, we have $5$ terms contributing $+1$ and $4$ terms contributing $+1$, hence the derivative equals $+1$. 
Hence, the derivative changes sign from negative to positive at $x = 5$ and therefore $x = 5$ is the minimum.
The other examples work in the same way.
A: For finding minimum in these type of equations, we take the average of the values, and put it equal to $x$, because we want to find $x$ such that it is equidistant from the points given. 
Like for first, $$\frac{(1+2+\cdots+9)}{10}=5$$
Similarly for second, $$\frac{(1+2+\cdots+99)}{100}=50$$
A: $|x-7|$ is the distance between $x$ and $7$.
Look at the sequence of numbers $1,2,3,4,5,6,7,8,9$.  The one in the middle is $5$.  Four of the numbers are less than $5$ and four are bigger.  In other words, $5$ is the median.
Now suppose $x$ is somewhere between $3$ and $4$.  Three of the numbers in the list are less than $x$ and six are bigger.  That means if $x$ gets bigger, it's getting farther from three of the numbers and closer to six of them.  Since those it's getting closer to outnumber those it's getting farther from, the sum of its distances to all of them is getting smaller.
Similarly, if $x$ is between $7$ and $8$, that total distance from $x$ to all others gets smaller if $x$ gets smaller.
Summary: the total distance --- the sum of all distances from $x$ to the others --- gets smaller whenever $x$ moves toward the number that's in the middle.
A: Caveat: The derivative is not the best tool for this.  But if you want to use the derivative to consider such expressions, consider rewriting the expressions as $g(x)=\sqrt{(x-1)^2}+\sqrt{(x-2)^2}+\cdots+\sqrt{(x-n)^2}.$  Then the derivative is
$$g'(x)=\frac {x-1}{\sqrt{(x-1)^2}}+\frac {x-2}{\sqrt{(x-2)^2}}+\cdots+\frac {x-n}{\sqrt{(x-n)^2}}$$
For each $i$, the value at $f_i(x)=\frac {x-i}{\sqrt{(x-i)^2}}$ is undefined for $x=i$, but negative from the negative side and positive from the positive side.
Further, it is clear that for each $i$ we have $f_i(x)=\pm 1, x\ne i$, and for $k\lt i$ we have $f_i(k)=\frac {k-i}{\sqrt{(k-i)^2}}=-1$ and for $k\gt i,f_i(k)=\frac {k-i}{\sqrt{(k-i)^2}}=1$, so $g'(x)$ has value $0$ or nearest to $0$ at the midpoint $n+1\over 2$.  Thus the original function has a minimum or maximum at $x={n+1\over 2}$.  Since the derivative is negative for $x\lt {n\over 2}$ and positive for $x\gt {n+2\over 2}$ we have ${n+1\over 2}$ is a minimum:  if $n$ is odd, ${n+1\over 2}$ is the only minimum, if $n$ is even, then $x\in [\frac n2,\frac n2+1]\implies f(x)=0\implies x={n+1\over 2}$ is one amongst an interval of minimums.
