The catenary, help with the equation for a hanging chain.

The mass in $mgh$ is locally $dm=\rho\,ds$, where $\rho$ is the lineic mass and $ds$ the element of length, also written $ds=\sqrt{dx^2+dy^2}=dx\sqrt{1+y'^2}$.

Hence the total energy (with $h\equiv y$)

$$\rho g\int y\sqrt{1+y'^2}dx.$$


By the Euler-Lagrange equation,

$$\frac{\partial f}{\partial y}=\frac{d}{dx}\frac{\partial f}{\partial y'},$$

i.e.

$$\sqrt{1+y'^2}=\frac{d}{dx}\frac{yy'}{\sqrt{1+y'^2}}=\frac{y'^2+yy''}{\sqrt{1+y'^2}}-\frac{yy'^2y''}{(1+y'^2)^{3/2}},$$

$$(1+y'^2)^2=(y'^2+yy'')(1+y'^2)-yy'^2y'',$$

$$1+y'^2-yy''=0,$$ $$\frac{y'}y-\frac{y'y''}{y'^2+1}=0,$$ $$(\log y)'=\left(\frac12\log(y'^2+1)\right)',$$ $$Cy^2=y'^2+1,$$ $$\frac{y'}{\sqrt{Cy^2-1}}=1$$ and finally

$$\frac1{\sqrt C}\text{arcosh}\sqrt Cy=x+C'$$


You more or less already answered it: You need to understand how mgh translates. So \rho = m and y = h and the g is already in the Formula. Work = Force *segement and the Energy is an integrated version of this.

For getting the minimizer you might try the Euler-Lagrange Equations.