- 5th Aug 2022
- 06:03 am
function A10Prob1_noloop_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
?lls function A10Prob1_noloop_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: A10, Problem 1
% Author: Drew Kang
% Team ID: ###-##
% Academic Integrity:
% [] I worked with one or more peers but our collaboration
% maintained academic integrity.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ____________________
%% VARIABLE INITIALIZATION
format longe
increment = 2*radius/100;
height = 0:increment:2*radius;
volume = []; % Initialize
%% ____________________
%% NESTED STRUCTURE
if radius>=100 && radius<=500
volume = pi*radius*height.^2 - (pi/3)*height.^3; % compute volume
disp('----------------------------------------------------')
disp(' Heignt (cm) Volume(cm^3)')
disp('----------------------------------------------------')
end
if isempty(volume) == 0 % isempty() is a Matlab function to check vol is empty
disp([height' volume'])
plot(height,volume)
xlabel('Height, cm')
ylabel('Volume,cm^3')
title('Filled volume of a sphere')
else
display('Give radius between 100 and 500 cm')
end
end
%% ____________________
%% RESULTS
% >>A10Prob1_noloop_sphereVol_kang401(250)
% ----------------------------------------------------
% Heignt (cm) Volume(cm^3)
% ----------------------------------------------------
% 0 0
% 5.000000000000000e+000 1.950405439103663e+004
% 1.000000000000000e+001 7.749261878854822e+004
% 1.500000000000000e+001 1.731802950291373e+005
% 2.000000000000000e+001 3.057816849494065e+005
% 2.500000000000000e+001 4.745113903859583e+005
% 3.000000000000000e+001 6.785840131753953e+005
% 3.500000000000000e+001 9.172141551543200e+005
% 4.000000000000000e+001 1.189616418159335e+006
% 4.500000000000000e+001 1.495005404027043e+006
% 5.000000000000000e+001 1.832595714594046e+006
% 5.500000000000000e+001 2.201601951696947e+006
% 6.000000000000000e+001 2.601238717172348e+006
% 6.500000000000000e+001 3.030720612856853e+006
% 7.000000000000000e+001 3.489262240587064e+006
% 7.500000000000000e+001 3.976078202199582e+006
% 8.000000000000000e+001 4.490383099531011e+006
% 8.500000000000000e+001 5.031391534417953e+006
% 9.000000000000000e+001 5.598318108697010e+006
% 9.500000000000000e+001 6.190377424204788e+006
% 1.000000000000000e+002 6.806784082777885e+006
% 1.050000000000000e+002 7.446752686252905e+006
% 1.100000000000000e+002 8.109497836466452e+006
% 1.150000000000000e+002 8.794234135255128e+006
% 1.200000000000000e+002 9.500176184455534e+006
% 1.250000000000000e+002 1.022653858590427e+007
% 1.300000000000000e+002 1.097253594143795e+007
% 1.350000000000000e+002 1.173738285289316e+007
% 1.400000000000000e+002 1.252029392210652e+007
% 1.450000000000000e+002 1.332048375091462e+007
% 1.500000000000000e+002 1.413716694115407e+007
% 1.550000000000000e+002 1.496955809466147e+007
% 1.600000000000000e+002 1.581687181327341e+007
% 1.650000000000000e+002 1.667832269882651e+007
% 1.700000000000000e+002 1.755312535315737e+007
% 1.750000000000000e+002 1.844049437810259e+007
% 1.800000000000000e+002 1.933964437549876e+007
% 1.850000000000000e+002 2.024978994718251e+007
% 1.900000000000000e+002 2.117014569499042e+007
% 1.950000000000000e+002 2.209992622075910e+007
% 2.000000000000000e+002 2.303834612632515e+007
% 2.050000000000000e+002 2.398462001352517e+007
% 2.100000000000000e+002 2.493796248419578e+007
% 2.150000000000000e+002 2.589758814017355e+007
% 2.200000000000000e+002 2.686271158329512e+007
% 2.250000000000000e+002 2.783254741539708e+007
% 2.300000000000000e+002 2.880631023831601e+007
% 2.350000000000000e+002 2.978321465388854e+007
% 2.400000000000000e+002 3.076247526395125e+007
% 2.450000000000000e+002 3.174330667034076e+007
% 2.500000000000000e+002 3.272492347489367e+007
% 2.550000000000000e+002 3.370654027944659e+007
% 2.600000000000000e+002 3.468737168583611e+007
% 2.650000000000000e+002 3.566663229589881e+007
% 2.700000000000000e+002 3.664353671147134e+007
% 2.750000000000000e+002 3.761729953439029e+007
% 2.800000000000000e+002 3.858713536649223e+007
% 2.850000000000000e+002 3.955225880961379e+007
% 2.900000000000000e+002 4.051188446559158e+007
% 2.950000000000000e+002 4.146522693626218e+007
% 3.000000000000000e+002 4.241150082346220e+007
% 3.050000000000000e+002 4.334992072902826e+007
% 3.100000000000000e+002 4.427970125479694e+007
% 3.150000000000000e+002 4.520005700260484e+007
% 3.200000000000000e+002 4.611020257428858e+007
% 3.250000000000000e+002 4.700935257168476e+007
% 3.300000000000000e+002 4.789672159662998e+007
% 3.350000000000000e+002 4.877152425096084e+007
% 3.400000000000000e+002 4.963297513651395e+007
% 3.450000000000000e+002 5.048028885512589e+007
% 3.500000000000000e+002 5.131268000863329e+007
% 3.550000000000000e+002 5.212936319887274e+007
% 3.600000000000000e+002 5.292955302768083e+007
% 3.650000000000000e+002 5.371246409689418e+007
% 3.700000000000000e+002 5.447731100834940e+007
% 3.750000000000000e+002 5.522330836388308e+007
% 3.800000000000000e+002 5.594967076533183e+007
% 3.850000000000000e+002 5.665561281453222e+007
% 3.900000000000000e+002 5.734034911332090e+007
% 3.950000000000000e+002 5.800309426353445e+007
% 4.000000000000000e+002 5.864306286700947e+007
% 4.050000000000000e+002 5.925946952558257e+007
% 4.100000000000000e+002 5.985152884109034e+007
% 4.150000000000000e+002 6.041845541536939e+007
% 4.200000000000000e+002 6.095946385025634e+007
% 4.250000000000000e+002 6.147376874758779e+007
% 4.300000000000000e+002 6.196058470920028e+007
% 4.350000000000000e+002 6.241912633693050e+007
% 4.400000000000000e+002 6.284860823261501e+007
% 4.450000000000000e+002 6.324824499809040e+007
% 4.500000000000000e+002 6.361725123519333e+007
% 4.550000000000000e+002 6.395484154576030e+007
% 4.600000000000000e+002 6.426023053162801e+007
% 4.650000000000000e+002 6.453263279463303e+007
% 4.700000000000000e+002 6.477126293661197e+007
% 4.750000000000000e+002 6.497533555940139e+007
% 4.800000000000000e+002 6.514406526483795e+007
% 4.850000000000000e+002 6.527666665475822e+007
% 4.900000000000000e+002 6.537235433099879e+007
% 4.950000000000000e+002 6.543034289539632e+007
% 5.000000000000000e+002 6.544984694978735e+007
%% ____________________
%?ADEMIC INTEGRITY STATEMENT
% I have not used source code obtained from any other unauthorized
% source, either modified or unmodified. I have not provided
?cess to my code to anyone in any way. The program I am
% submitting is my own original work.