Solution (source code)

= Solution

For an arbitrary smooth variation $u_t=u+t\varphi$, differentiation under the integral gives
$$
\left.\frac d{dt}E(u_t)\right|_{t=0}
=\int_M\left(g^{ij}\partial_i u\,\partial_j\varphi-f\varphi\right)\sqrt{|g|}\,dx.
$$
Since $M$ is compact without boundary, integration by parts turns this into
$$
-\int_M\left[
\frac1{\sqrt{|g|}}\partial_j\left(\sqrt{|g|}g^{ij}\partial_i u\right)+f
\right]\varphi\,d\operatorname{vol}_g.
$$
The <fundamental lemma of the calculus of variations> therefore gives the <Euler-Lagrange equation>
$$
-\frac1{\sqrt{|g|}}\partial_j\left(\sqrt{|g|}g^{ij}\partial_i u\right)=f,
$$
or equivalently $-\Delta_gu=f$ for the <Laplace-Beltrami operator>.