4.2the if-else statement 51
The if-else statement
(http://www.eng.ed.ac.uk/teaching/courses/matlab/unit04/if-else-
statement.shtml)
The following example is solved in the screencast:
Water level in a water tower†
The tank in a water tower has the geometry shown in Figure 14 (the lower
part is a cylinder and the upper part is an inverted frustum cone). Inside the
tank there is a float that indicates the level of the water. Write a user-defined
function that determines the volume of water in the tank from the position
(height) of the float. The volume for the cylindrical section of the tank is given
by:
V=π·12.5^2 ·h
The volume for the cylindrical and conical sections of the tank is given by:
V=π·12.5^2 · 19 +
1
3 π(h−^19 )(12.5
(^2) +12.5rh+rh (^2) ),
where rh=12.5+10.5
14
(h− 19 )
[h=8 m,V=3927 m^3 ;h=25.7 m,V=14115 m^3 ]
†Question adapted from Gilat, A. (2008).MATLAB : An Introduction With Applications. John
Wiley & Sons, Inc., 3rd edition. Copyright©2008 John Wiley & Sons, Inc. and reprinted
with permission of John Wiley & Sons, Inc.
12.5 m
h
14 m rh
19 m
23 m
Figure 14: Water level in a water tower