Find $f(x)$ if $f\left(\frac{x+y}{3}\right)=\frac{2+f(x)+f(y)}{3}$ $f : \mathbb{R} \to \mathbb{R}$ is a differentiable function satisfying $$f\left(\frac{x+y}{3}\right)=\frac{2+f(x)+f(y)}{3}$$
if $f'(0)=2$, find the function
My Try:
we have $$f\left(\frac{x+y}{3}\right)-\frac{f(y)}{3}=\frac{2+f(x)}{3}$$ $\implies$
$$\frac{f\left(\frac{x+y}{3}\right)-\frac{f(y)}{3}}{\frac{x}{3}}=\frac{2+f(x)}{x}$$ 
Now taking Limit $x \to 0$ we have
$$\lim_{x \to 0}\frac{f\left(\frac{x+y}{3}\right)-\frac{f(y)}{3}}{\frac{x}{3}}=\lim_{x \to 0}\frac{2+f(x)}{x}$$ 
$\implies$
$$f'\left(\frac{y}{3}\right)=\lim_{x \to 0}\frac{2+f(x)}{x}$$ 
Now since LHS to be finite , we need $0/0$ form in RHS, hence $f(0)=-2$
Now by L'Hopital's Rule we get
$$f'\left(\frac{y}{3}\right)=f'(0)=2$$
Integrating we get
$$3f\left(\frac{y}{3}\right)=2y+c$$
Putting $y=0$ we get $c=-6$
So
$$3f\left(\frac{y}{3}\right)=2y-6$$
So $$f(y)=2y-2$$
Hence $$f(x)=2x-2$$
But this function is not satisfying given functional equation. 
What went wrong?
 A: Using $x=y=0$ in the functional equation we can see that $f(0)=2$. Further note that $$f(x+h)=\frac{2+f(3x)+f(3h)}{3}, f(x) =\frac{2+f(3x)+f(0)}{3}$$ so that $$\frac{f(x+h) - f(x)} {h} =\frac{f(3h)-f(0)}{3h}$$ Taking limits as $h\to 0$ we get $f'(x) =f'(0)=2$ and thus $f(x) =2x+c$ and from $f(0)=2$ we get $c=2$ so that $f(x) =2x+2$. You can check that it satisfies the functional equation. 
A: One readily verifies that the affine map $a(x) = 2x+2$ is a differentiable function which solves both the defining equation for $f$ and the derivative constraint $f'(0) = 2$.
Let's prove now the uniqueness of this solution. The defining equation can be rewritten $f\left( \frac{x+y}{3} \right) - \frac{f(x) + f(y)}{3} = \frac{2}{3}$. Differentiating with respect to $x$, we get $f'\left( \frac{x+y}{3} \right) - f'(x)=0$ regardless of the values $x$ and $y$, so that $f'(x)$ is a constant. The constraint $f'(0)=2$ thus yields $f'(x) \equiv 2$, which integrates to $f(x) = 2x+c$. Substituting this result into the defining equation for $f$ readily yields $c=2$.
Remark: Paramanand Singh's answer is better than mine in that it proves that $f$ is differentiable at every point by only using its defining equation and the assumption that it is differentiable at $0$. In that respect it is quite instructive. Be aware however that such a proof is in general rather difficult, hence the frequent assumption that $f$ is differentiable ; one doesn't need then to rely on the definition of a derivative, but can rather merely differentiate the defining equation as I did above.
