Available under Creative Commons-ShareAlike 4.0 International License.
Now, let’s incorporate the input command in AcetyleneBottleInteractive.m as shown below and the subsequent figure:
% This script computes the volume of an acetylene bottle % user is prompted to enter % a radius r for a hemispherical top % a height h for a cylindrical part r=input('Enter the radius of acetylene bottle in meters '); h=input('Enter the height of cylindrical part of acetylene bottle in meters '); Vol_top=(2*pi*r^3)/3; % Calculating the volume of hemispherical top [m3] Vol_cyl=pi*r^2*h; % Calculating the volume of cylindrical bottom [m3] Vol_total=Vol_top+Vol_cyl % Calculating the total volume of acetylene bottle [m3]
Figure 4.5 Interactive script that computes the volume of acetylene cylinder.
The command window upon run will be as follows, note that user keys in the radius and height values and the same input values result in the same numerical answer as in example (Example 4.1) which proves that the computation is correct.
Figure 4.6 The same numerical result is obtained through interactive script.
- 瀏覽次數:1180