Can You Bake the Optimal Cake Using Calculus?
Problem Description
FiveThirtyEight's Oliver Roeder challenged readers to maximize the volume of a cake comprised of three cylindrical tiers subject to the constraint that the cake must fit beneath a glass cone of a prescribed size in The Riddler:
A mathematician who has a birthday coming up asks his students to make him a cake. He is very particular (he is a constructive set theorist, which explains a lot) and asks his students to make him a three-layer cake that fits under a hollow glass cone he has on his desk. He requires that the cake fill up the maximum amount of volume under the cone as possible and that the layers of the cake have straight vertical sides. What are the thicknesses of the three layers of the cake in terms of the height of the glass cone? What percentage of the cone's volume does the cake fill?
Our goal is to adjust the height and radius of each of the three tiers in order to maximize the volume of the cake.
Drawing a Diagram
While there may be an elegant solution using only elementary techniques, this problem immediately stood out to me as one that could be solved using multivariable calculus optimization.
Let's start with a cone of height $h$ and radius $r$. Let the height of each tier of the cake be $h_1$, $h_2$, and $h_3$. Also let the remaining space between the third tier and the top of the cone be $h_0 = h - h_1 - h_2 - h_3$. Finally, let the radius of each tier be $r_1$, $r_2$, and $r_3$.
A Formula for the Volume of the Cake
The volume of the entire cone is just $V_{\text{cone}} = \frac{\pi r^2 h}{3}$. The combined volume of the three-tiered cake is the sum of the volumes of the individual cylindrical tiers:
At first, maximizing $V_{\text{cake}}$ might seem very difficult since there are so many variables. Luckily, the diagram reveals a set of four similar right triangles, which leads to the following proportions:
These proportions give us:
Plugging these back into $V_{\text{cake}}$ and using the substitution $a = h_1$, $b = h_2$, $c = h_3$, $H = h$, and $R = r$ for clarity, we get the volume as a function of three variables.
Maximize the Volume Using the Gradient
This equation is perfect for finding the gradient $\nabla V = \left\langle \frac{\partial V}{\partial a}, \frac{\partial V}{\partial b}, \frac{\partial V}{\partial c} \right\rangle$. As usual, set $\nabla V = \vec{0}$ and solve. We get four solutions, the first two of which are extraneous if we require three tiers of nonzero volume:
Test Candidates Using the Hessian Determinant
We verify which solution is our desired maximum using the second derivative test for a function of three variables — the Hessian determinant. Testing $\left(\frac{H}{6}, \frac{H}{6}, \frac{H}{6}\right)$ gives a saddle point. On the other hand, $\left(\frac{H}{4}, \frac{H}{4}, \frac{H}{4}\right)$ gives our desired local maximum.
The Solution
With our local maximum at $(a,b,c) = \left(\frac{H}{4}, \frac{H}{4}, \frac{H}{4}\right)$, the three tiers each have height $\frac{h}{4}$, with a gap of $\frac{h}{4}$ at the top. The maximum volume is:
And the maximum percentage of the cone filled with cake:
Mathematica Demo
I created a Mathematica demo of my solution. Here's the interactive manipulate:
You can download the full Mathematica notebook:
← Back to Blog