Matlab Task on sphereVol

Matlab Task on sphereVol

function A09Prob1_sphereVol_kang401(radius)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
% Calls function A09Prob1_sphereVol_kang401(radius) with input as radius
%
% Input Arguments
% Takes radius as input
%
% 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: ###-##
% Academic Integrity:
% [] I worked with one or more peers but our collaboration
% maintained academic integrity.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% NESTED STRUCTURE
h=[]; %Initialize
vol = []; % Initialize
if radius>=100 && radius<=500
for height = 0:100:2*radius
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
%% ____________________
%% ACADEMIC INTEGRITY STATEMENT
% I have not used source code obtained from any other unauthorized
% source, either modified or unmodified. Neither have I provided
% access to my code to another. The function I am submitting
% is my own original work.