
Available under Creative Commons-ShareAlike 4.0 International License.
Now, let’s open AcetyleneBottleInteractive.m file and modify it by using the disp command. First save the file as AcetyleneBottleInteractiveDisp.m, so that we don’t accidentally introduce errors to a working file and also we can easily find this particular file that utilizes the disp command in the future. The new file should contain the code below:
% 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 clc % Clear screen disp('This script computes the volume of an acetylene bottle') 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] disp(' ') % Display blank line disp('The volume of the acetylene bottle is') % Display text disp(Vol_total) % Display variable
Your screen output should look similar to the one below:
This script computes the volume of an acetylene bottle Enter the radius of acetylene bottle in meters .3 Enter the height of cylindrical part of acetylene bottle in meters 1.5 The volume of the acetylene bottle is 0.4807
- 瀏覽次數:1212