Optimal cylinder and hemispherical cap with unequal surface costs (source code)

= Optimal cylinder and hemispherical cap with unequal surface costs
{title2=$h=2(\alpha-1)r,\quad r^3=V/[2\pi(\alpha-2/3)]$}

Consider a cylinder of radius $r$, height $h\geq0$, and a hemispherical cap of the same radius, enclosing fixed volume $V$. Let the cylindrical wall cost $w>0$ per area and the cap cost $\alpha w$ per area, with no floor cost. Then $V=\pi r^2h+2\pi r^3/3$ and $C=2\pi wrh+2\pi\alpha wr^2$. Eliminating $h$ gives $C(r)=2wV/r+2\pi w(\alpha-2/3)r^2$, on $0<r\leq(3V/(2\pi))^{1/3}$.

For $\alpha>1$, its interior minimum satisfies the displayed formulas; the positive second derivative proves uniqueness. For $0<\alpha\leq1$, cost decreases throughout the feasible interval up to its endpoint, so the minimum has $h=0$ and is a hemisphere alone. At cap-to-wall cost ratio two, the optimal cylinder height is its diameter, $h=2r$. This boundary check is part of the <constrained optimization>, since a formal critical point can otherwise require negative height.