 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ENGR 132
% Program Description
% The code computes volume of a sphere as a function of height of fluid
% The input to function call is radius
% The function does not return any variable
% variable h and vol are vectors of height and volume
% volume is computed as a function of each height
% isempty() function is used to check if vector vol is empty
% If vol is empty, then do not plot
% The code will plot if radius is >=100 and <=500 in cm
%
% Function Call
%
% Input Arguments
%
% Output Arguments
% The function does not return any output.
% However, it displays plot of volume as a function of height
%
% Assignment Information
% Assignment: A09, Problem 1
% Author: Drew Kang
% Team ID: ###-##
% [] I worked with one or more peers but our collaboration
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% NESTED STRUCTURE
h=[]; %Initialize
vol = []; % Initialize
volume = pi*radius*height*height – (pi/3)*height.^3; % compute volume
h = [h;height]; % update height vector
vol = [vol;volume]; % update volume vector
end
end
if isempty(vol) == 0 % isempty() is a Matlab function to check vol is empty
plot(h,vol)
xlabel(‘Height, cm’)
ylabel(‘Volume,cm^3’)
title(‘Filled volume of a sphere’)
end
end
%% ____________________