Word Problems and the Algorithmic Process for Multistep Problem Solving
In this example, we demonstrate an important process for solving multistep problems in Python which we will apply on almost every example from now on. Suppose we want to create a dome (a cylinder with a hemisphere on top) which has a volume of 4 cubic meters. We’d like to plot a graph of the surface area of the dome as a function of the radius of the cylinder/hemisphere. Of course, if we just type this word problem into Python and press SHIFT/ENTER, we would not get a solution-most likely we’d get an error instead. The moral of the story is-when you turn your computer ON, you don’t turn your brain OFF. They have to work together to solve problems of ANY type. So what is our strategy? On ANY multistep problem, the best strategy is to list the steps you would do to solve it by hand. Then, write down the key Python command(s) which allow you to perform each step. In this problem, the steps we need are the following:
1) Write formulas for the volume and surface area of the dome
2) Set the volume equal to 4 and solve for the height
3) Substitute the height into the surface area formula
4) Plot the resulting expression
A simple search tells us that V = pi*r^2*h + ⅔*pi*r^3 (the volume of the cylinder plus half the volume of a sphere) and S = 2*pi*r*h + 2*pi*r^2 (the lateral area of a cylinder plus half the area of a sphere). So for STEP 1, we define r and h as symbolic variables (note pi is a predefined constant in Python), then define V and S. For STEP 2, we use the Python command solve, noting that solving V = 4 is the same as solving V-4 = 0. For STEP 3, we use the Python command subs. And finally, for STEP 4, we use the plot command. NOTE that all of these commands were introduced in previous videos, so if you do not know how to use a particular command, refer to that video or the online help documentation. No domain was specified, so we pick one to start with, such as [0, 10], and adjust it and our range if we need to. The important thing to understand in this video is the process: List the steps you would do to solve the problem by hand, then determine the key Python command(s) which allow you to perform each step.