On each interval (ak,ak+1) :
f(x)=i=1∑k(ai−x)+i=k+1∑k(x−ai)=(n−2k)x+i=1∑kai−i=k+1∑kai
Thus, f(x) is decreasing on (ak,ak+1) as long as n−2k>0, i.e. k<n/2, increasing as soon as k>n/2.
There are two cases:
If n is odd, n=2p+1, there is a unique minimum, attained at the middle point ap+1, and its value is:
f(an+1)=−a1−...−an+an+2+...+a2p+1
If n is even, n=2p, the function attains its minimum on the middle interval [ap,ap+1] and its value is:
−a1−...−ap+ap+1+...+a2p
Comments