This Puzzlet appears at first glance to be a problem in simple algebra. However, once you have analysed the available information and produced a working formula to derive the answer, it's obviously not so straightforward ...
The IBasic program below describes the problem in the opening REM statements, then provides the code to solve it.
' Puzzlet #011.
' A close-tolerance project in the aerospace industry
' specifies the manufacture of a 100-metre high cyclinder
' and a cube, both having exactly the same radius. The
' overall volume of material used must be within 0.001
' cubic metres of 100 cubic metres. What is the radius
' to 6 decimal places of accuracy, and what is the volume
' of surplus material to 4 decimal places of accuracy?
' By Dave Ellis.
def lo, mid, hi, pi, radius, volume: double
def midValue, hiValue: double
pi = 3.141592654
lo = 0.1
hi = 10
openconsole
print "Calculating ...": print
do
mid = 0.5*(lo + hi)
midValue = pi*mid^ 2*(mid + 75) - 75
hiValue = pi*hi^ 2*(hi + 75) - 75
if hiValue*midValue > 0
hi = mid
else
lo = mid
endif
until abs(midValue)< .001
print "radius: ", using ("##.#######", mid), " metres.": print
volume = pi*mid*mid*(100 + 4*mid/3)
print "volume: ", using ("###.####", volume), " cubic metres"
print: print "Press any key to close ..."
do: until inkey$ <> ""
closeconsole
end
PROGRAM NOTES
From the formula for the volumes of a cylinder and a sphere, we can say:
100.pi.r ² + 4.pi.r³/ 3 = 100
so, 75.pi.r² + pi.r³ = 75
and pi.r² .(75 + r) - 75 = 0
This little formula is difficult to solve by traditional methods, but very simple using the bisection method. Bisection works like this:
- Make an intelligent guess as to the range in which the answer is likely to lie - in this case 0.1 to 10 metres, denoted lo and hi in the code.
- Bisect the range. The bisector is (lo + hi)/2, denoted mid in the code.
- Plug this value into the derived formula, and then use the higher value as well, to give midValue and hiValue values.
- If midValue was negative, the trial value of mid was too low, so we have to have to substitute hi in its place.
- If midValue was positive, we can reduce its value toward zero by substituting lo in its place.
- Now test the absolute value of midValue. If it's greater than 0.001 metres, it's not accurate enough and we have to go around the loop again to the second paragraph (bisect the range). If it's less than 0.001 metres, that'll do, and we can exit the loop.
All the above actions are accomplished within the DO loop in the code. The rest of the code just prints the result in a tidy format, calculating the volume for printing as well.
When you run the code, it produces the inset screen.
The radius is calculated to the required degree of accuracy, and the final volume is within the limits specified.
Calculating ...
radius: 0.5620893 metres
volume: 100.0007 cubic metres
Press any key to close ...
MAIN MENU
DOWNLOAD CODE
ARCHIVES
Site design/maintenance: Dave Ellis E-mail me!
Last Updated: February 22nd, 2004.