您在這裡

Example 4.2

20 一月, 2016 - 09:21

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]
media/image6.png
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.

media/image7.png
Figure 4.6 The same numerical result is obtained through interactive script.