Please solve by using Matlab The figure below shows a cylindrical tank of height
ID: 2079158 • Letter: P
Question
Please solve by using Matlab
The figure below shows a cylindrical tank of height H, and radius r with a spherical cap on each end (also with radius r). If the height of the liquid is h, what is the volume of the liquid in the tank? Write a Matlab script which will allow the user to enter different values of h, return the volume, and only stop when the user enters a negative value for h. (Massive hint: there are three possible cases for h If h is less than r, we need the volume of a partially filled sphere, given by V = 1/3 pih^2(3r - h) If h is greater than r (the lower hemisphere is filled), but less than H-r (the liquid has not reached the upper hemisphere), the volume is given by V = 2/3 pi r^3 + pi r^2 (h - r)Explanation / Answer
line1=('enter the radius');
r=input(line1);
line2=('enter the height tank');
H=input(line2);
line=('enter the water level');
h=input(line);
if (h>=0)&& (h<r) && (r>0) && (H>0)
v=1/3*pi*h^2*(3*r-h);
disp(v);
elseif (h>=r) && (h<(H-r)) && (r>0) && (H>0)
v=(2/3)*pi*r^3+pi*r^2*(h-r);
disp(v);
elseif (h>=(H-r))&&(h<=H) && (r>0) && (H>0)
v=pi*r^2*(H-2*r)+(4/3)*pi*r^3-(1/3)*pi*(H-h)^2*(3*r-H+h);
disp(v);
else
linee=('Values are wrong, Enter Again');
disp(linee);
end