You are here

Example 4.1

20 January, 2016 - 09:21

A cylindrical acetylene bottle with a radius r=0.3 m has a hemispherical top. The height of the cylindrical part is h=1.5 m. Write a simple script to calculate the volume of the acetylene bottle.

To solve this problem, we will first apply the volume of cylinder equation (4.1). Using the volume of sphere equation (4.2), we will calculate the volume of hemisphere (4.3). The total volume of the acetylene bottle is found with the sum of volumes equation (4.4).

V_{\textrm{cylinder}}=\pi r^2hV_{\textrm{sphere}}=\frac{4}{3}\pi r^3V_{top}=\frac{2}{3}\pi r^3
V_{acetylene}_{ }_{bottle} =V_{cylinder}+V_{top}

To write the script, we will use the built-in text editor. From the menu bar select File > New > Script. The text editor window will open in a separate window. First save this file as AcetyleneBottle.m. In that window type the following code paying attention to the use of percentage and semicolon symbols to comment out the lines and suppress the output, respectively.

    % This script computes the volume of an acetylene bottle with a radius r=0.3 m,
% a hemispherical top and a height of cylindrical part h=1.5 m.
r=0.3;                      % Radius [m]
h=1.5;                      % Height [m]
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/image4.png
Figure 4.3 Script created with the built-in text editor. 
 

After running the script by pressing the green button in the Text Editor tool bar, the output is displayed in the command window as shown below.

media/image5.png
Figure 4.4 The MATLAB output in the command window.