Safari 11:25 ANM * 100%; \" Programming Assignment 6 A+ ENGR 215 Fall 2016 Programming with MATLAB (Due Date: Nov, 15th, 2016) The script must be well-commented so that your work (Submit a MATLAB script called can be followed.) 16esnh\" The figure below shows a cylindrical tube of height and radius r with a spherical cap on both ends (also of radius r) If the height of the liquid is , what is the volume of the liquid in the tube? The calculation of the volume of liquid in the tube depends upon the relationship between h, Hand r. If h is less than or equal to r, we need the volume v of a partially filled sphere given by If h is greater than r but less than or equal to Lr we need the volume of a fully filled hemisphere plus the volume of a cylinder of height hr: 3 or the sum of both the upper and lower hemispheres) plus the volume of a cylinder of height 2r \'If h is greater than H-r we need the volume of a fully filled sphere (that would be the equivalent, minus the volume of the pataly empty upper hemisphere of height H-h Write a MATLAB program that asks the user to input the three values required for caleulation (h, H and r) and calculates the volume of the lquid level. The output (using pint) should list the three input values plus the calculation rounding of all the values to 2 decimal places Your program should end (you can use the return command to end a MATLAB program) if any invalid inputs occur, hence your program should check for invalid values: negative numbers as input values and values where the liquid is too high for the tube values where H
function [] = fall16assn6()
HArr = input(\'Enter the height of the tube: \');
hArr = input(\'Enter the height of the liquid: \');
rArr = input(\'Enter the radius of the tube: \');
for i=1:size(hArr,2)
h = hArr(1,i);
H = HArr(1,i);
r = rArr(1,i);
if( h < 0 || H < 0 || r < 0 )
fprintf(\'Invalid inputs\ \');
return
end
if( h > H || H < 2*r )
fprintf(\'Invalid inputs\ \');
return
end
if( h <= r )
V = (1/3)*pi*h*h(3*r - h );
elseif( h > r && h <= H-r )
V = (2/3)*pi*(r^3) + (pi*(r^2)*(h-r));
else
V = (4/3)*pi*(r^3) + (pi*(r^2)*(H-2*r));
V = V - (1/3)*pi*((H-h)^2)*(3*r - H + h);
end
fprintf(\'For H = %.2f, h = %.2f and r = %.2f; v = %.2f\ \',H,h,r,V);
end
return;
end