Prove that $f:\mathbb R^n\to\mathbb R$ is affine if and only if it is convex and concave Suppose $f:\mathbb{R}^n\to \mathbb{R}$ is both convex and concave, how to prove that $f$ is linear? or exactly speaking, $f$ is affine?
I thought for the whole day, but I cannot figure it out. 
When I was working on this problem, I met another problem, are all the convex function continuous? If not, is there any counter example?
Actually, I can prove for one dimensional case, in which $f:\mathbb{R}\to \mathbb{R}$. However, I cannot generalize it into n dimensional cases.
By the way, I use definition for convex(concave) like this:
$$f(t\vec{x}+(1-t)\vec{y})\leq(or \geq) tf(\vec{x})+(1-t)f(\vec{y}), \forall t\in[0,1].$$
Thank you so much!
 A: I think it becomes more clear when we simply apply the definition of convexity and concavity.
From the convexity of $f$ we have for $x_1, x_2\in \mathbb{R^n}$ and $\lambda \in [0,1]$$$f((1-\lambda)x_1 + \lambda x_2) \le (1-
\lambda)f(x_1)+\lambda f(x_2)$$
and similarly for concavity we have $$f((1-\lambda)x_1 + \lambda x_2) \ge (1-
\lambda)f(x_1)+\lambda f(x_2)$$
Thus it follows that $$f((1-\lambda)x_1 + \lambda x_2) = (1-
\lambda)f(x_1)+\lambda f(x_2)$$
We often think of $(1-\lambda)x_1 + \lambda x_2$ as a point on the line segment between $x_1$ and $x_2$. Similarly from above we can see that $f((1-\lambda)x_1 + \lambda x_2)$ lies on the line segment  between $f(x_1)$ and $f(x_2)$. Since we have chosen $x_1$ and $x_2$ arbitrarily it starts to become apparent why $f$ is affine. If we recall, an affine function takes the form $ax+b$ where $a \in \mathbb{R^n}$ and $ b \in \mathbb{R}$ which is a line.
A: Let $g(x) = f(x) - f(0)$.  It suffices to show that $g$ (which is also both convex and concave, and satisfies $g(0)=0$) is linear.  Next, note that for $t > 1$, $x = (1/t) (tx) + (1 - 1/t) (0)$.
That should give you a good start...
A: Whether convexity implies continuity depends on the domain (are you on a bounded domain or all of $\mathbb{R}^n$?). Consider, e.g., a smiling frog; the graph of the function is the smile, but at the end points of the smile, it is the eyes. That's a convex but not continuous function.
A: If $f$ has 
a second derivative,
then the two requirements imply that
$f'' \ge 0$
and
$f'' \le 0$
so that
$f'' = 0$
which implies that
$f$ is linear.
