Show the functional is convex. I am trying to show the functional $f(x,\xi)$ is convex w.r.t. $\xi$, where
$$f(x,\xi) = \left( w(x) \xi - 2 x w(x) \sin \frac{\pi}{x} + \pi w(x) \cos(\frac{\pi}{x}) \right)^2.$$
I tried the following; For notational simplicity we put
$$g=2 x \sin \frac{\pi}{x} + \pi \cos\frac{\pi}{x}.,$$
and
$$f(x,\xi)= w^2(\xi-g)^2= w^2 (\xi^2 - 2 \xi g +g^2).$$
So it is sufficient to show that $\xi \mapsto \xi^2 - 2 \xi g +g^2$ is convex. Let $\lambda \in (0,1)$, and $\xi, \eta \in \mathbb R$,
\begin{align*}
    x, \lambda \xi + (1-\lambda) \eta \mapsto  &=  (\lambda \xi + (1-\lambda) \eta)^2 - 2 (\lambda \xi + (1-\lambda) \eta) g +g^2,\\
& =\lambda^2 \xi^2 - 2\lambda \xi g + \lambda g^2 + (1-\lambda)^2 \eta^2 - 2(1-\lambda) \eta + g (1-\lambda) g^2 + 2 \lambda (1-\lambda) xy.
\end{align*}
I stuck here, I do not know how to continue. Any help appreciated
 A: Lets start to show for $\lambda\in [0,1]$ the inequality
$$f(x,\lambda \xi_1 + (1-\lambda) \xi_2) - \lambda \xi_1 f( \xi_1) -  (1-\lambda) f(\xi_2) \geq 0$$
Let us start the calculation:
$$f(x,\lambda \xi_1 + (1-\lambda) \xi_2) - \lambda \xi_1 f( \xi_1) -  (1-\lambda) f(\xi_2) = \\
w^2(\lambda \xi_1 + (1-\lambda) \xi_2 -g)^2 - \lambda  w^2( \xi_1-g)^2 -  (1-\lambda) w^2(\xi_2-g)^2 = \\
w^2(\lambda (\xi_1-g) + (1-\lambda) (\xi_2 -g))^2 - \lambda  w^2( \xi_1-g)^2 -  (1-\lambda) w^2(\xi_2-g)^2= \\
w^2(\lambda^2 (\xi_1-g)^2 +2\lambda(1-\lambda)(\xi_1-g)(\xi_2 -g)  +  (1-\lambda)^2 (\xi_2 -g)^2 -\lambda( \xi_1-g)^2 -(1-\lambda)(\xi_2-g)^2  ) = \\
w^2( (\lambda^2-\lambda)(\xi_1-g)^2 + 2\lambda(1-\lambda)(\xi_1-g)(\xi_2 -g) + ((1-\lambda)^2 - (1-\lambda) ) (\xi_2 -g)^2) =\\
w^2(\lambda(1-\lambda)(\xi_1-g)^2 +2\lambda(1-\lambda)(\xi_1-g)(\xi_2 -g) + \lambda(1-\lambda) (\xi_2 -g)^2)=\\
\lambda(1-\lambda)w^2( (\xi_1-g)^2 + 2(\xi_1-g)(\xi_2 -g) + (\xi_2 -g)^2) = \\
\lambda(1-\lambda)w^2((\xi_1-g) + (\xi_2 -g))^2 \geq 0 
$$
(The last inequality is as a product of two nonnegative numbers and two square numbers is nonnegative)
