I want to prove that if a function $f:S\subset\mathbb{R}^n\longrightarrow\mathbb{R}$ is at the same time concave and convex, then the function is affine. That's it, there exist $a\in\mathbb{R}$ and $b\in\mathbb{R}$ such that for all $z\in S$, $f(z)=az+b$.
I now how to do it when the domain is $\mathbb{R}$ as I showed below, but I am having difficulties on extending the proof to $\mathbb{R}^n$.
To prove it in the case of $\mathbb{R}$ I did as follows:
$f$ is convex in $S$ if $\forall x,y\in S$ and $\forall\lambda\in[0,1]$: $$f(\lambda x+(1-\lambda)y)\leq\lambda f(x)+(1-\lambda)f(y)$$
$f$ is concave in $S$ if and only if $-f$ is convex in $S$. Let us note that saying that $-f$ is convex in $S$ is equivalent to say that:
$\forall x,y\in S$ e $\forall\lambda\in[0,1]$ $f(\lambda x+(1-\lambda)y)\geq\lambda f(x)+(1-\lambda)f(y)$
Thus, as $f$ is both concave and convex we have that $\forall x,y\in S$ e $\forall\lambda\in[0,1]$:
$ f(\lambda x+(1-\lambda)y)=\lambda f(x)+(1-\lambda)f(y)$
We now need to prove that $f(z)=az+b$.
To do so we'll take $z=\lambda x+(1-\lambda)y$. Note that $z\in[x,y]$ and that $\lambda=\dfrac{z-y}{x-y}$. Thus, we now have that $f(\lambda x+(1-\lambda)y)=f(z)$ and that: $$\lambda f(x)+(1-\lambda)f(y)=\dfrac{yf(x)-xf(y)}{y-x}+\left( \dfrac{f(y)-f(x)}{y-x}\right) z$$
Therfore: $$f(z)=\dfrac{yf(x)-xf(y)}{y-x}+\left( \dfrac{f(y)-f(x)}{y-x}\right) z$$ So by taking $a= \dfrac{f(y)-f(x)}{y-x}$ and $b=\dfrac{yf(x)-xf(y)}{y-x}$ we have $f(z)=az+b$ , as we wanted to prove.
My problem is that in $\mathbb{R}^n$ I can't assume that $z\in[x,y]$ as they are vectors and $a$ and $b$ wouldn't be in $\mathbb{R}$ as their denominator would be a vector.
Any help would be appreciated.