You are on page 1of 1

clc

disp('HORIZONTAL CYLINDRICAL TANK VOLUME')


a=input('Enter the length of the semi-major axis: ');
b=input('Enter the length of the semi-minor axis: ');
L=input('Enter the length of the tank: ');
h=input('Enter the water level inside the tank: ');
while h>2*b
disp('ERROR! The water level must not be greater than the length of the
minor axis.')
b=input('Enter the length of the semi-minor axis: ');
h=input('Enter the water level inside the tank: ');
end
while b>a
disp('Error! The major axis must be greater than the minor axis.')
a=input('Enter the length of the semi-major axis: ');
b=input('Enter the length of the semi-minor axis: ');
end
A=integtrap(@(y) 2*sqrt(b^2-y.^2),0,(h-b),1000);
vol=L*(a/b)*(pi*(b^2/2)+A);
fprintf('The volume of the liquid inside the tank is %.1f.\n',vol)
function I=integtrap(func,a,b,n)
%integtrap: composite trapezoidal rule quadrature
%I=integtrap(func,a,b,n)
%input:
%
func=name of function to be integrated
%
a,b=integration limits
%
n=number of segments
%ouput:
%
I=integral estimate
x=a;
h=(b-a)/n;
s=func(a);
for i=1:n-1
x=x+h;
s=s+2*func(x);
end
s=s+func(b);
I=(b-a)*s/(2*n);
end