Suppose you have a cylinder of height h with base diameter b (perhaps an empty pretzel jar), and you wish to know how many ping-pong balls of diameter d have been placed inside the cylinder. How could you determine this? This problem, along with the strategy for computing the lower bound on the number of ping-pong balls, is adapted from Starfield (1994).
A lower bound for this problem is found as follows. Define the following variables:
NL−Lower bound on the number of balls that fit into the cylinder.
Vcyl−The volume of the cylinder.
Vcube−The volume of a cube that encloses a single ball.
The lower bound NL is found by dividing the volume of the cylinder by the volume of the cube enclosing a single ball:
You are given the following values:
Type commands at the command line prompt to compute NL.
Create an m-file to solve Exercise 11.
To complicate your problem, suppose that you have not been given values for d, b, and h. Instead you are required to estimate the number of ping pong balls for many different possible combinations of these variables (perhaps 50 or more combinations). How can you automate this computation?
One way to automate the computation of NL for many different combinations of parameter values is to use a for loop. The following exercises ask you to develop several different ways that for loops can be used to automate these computations.
Add a for loop to your m-file from Exercise 12 to compute NL for b=8in, h=14in, and values of d ranging from 1.0in to 2.0in.
Modify your m-file from Exercise 13 to plot NL as a function of d for b=8in and h=14in.
Modify your m-file from Exercise 13 to compute NL for d=1.54in and various values of b and h.