% Convergence Team Lab

% Part 1

%%  Find the volume of two portions of a hemisphere.
%%  The functioin crossSection(x) computes the cross sectional area.

disp(['  ' ]) %  Get a blank line

X = 0;
volPartSphere = quad('crossSection', -3, X);
disp([' For x = ', num2str(X),' the volume of the piece of the hemisphere is ',...
         num2str(volPartSphere) ])

check = (4/3)*pi*3^3 / 4;
disp([' If everything is correct, then ', num2str(volPartSphere), ...
        ' must equal ', num2str(check)])

X = 1.5;
volPartSphere = quad('crossSection', -3, X);
disp([' For x = ', num2str(X),' the volume of the piece of the hemisphere is ',...
         num2str(volPartSphere) ])


% Part 2
%%  Compute the volume of the torus.
%  Find the volume at t = 2

t = 2;
vol = quad('areaShell', 1, t);
disp([' For x = ', num2str(t),' the volume of the torus is ', num2str(vol) ])

%  Find the volume at t = 3

t = 3;
vol = quad('areaShell', 1, t);
disp([' For x = ', num2str(t),' the volume of the torus is ', num2str(vol) ])

%% Put the volume in a function and do it again.

t = 2;
vol = volumeTorus(t) ;
disp([' For x = ', num2str(t),' the volume of the torus is ', num2str(vol) ])

t = 3;
vol = volumeTorus(t);
disp([' For x = ', num2str(t),' the volume of the torus is ', num2str(vol) ])

%%  Find the value of t so that the volume of that piece of
%%  the torus is 20.

tShell = fzero('volLess20', 2);
disp([' For problem 2.b the volume is 20 when x = ', num2str(tShell) ])


% Part 3

%%  Find the value of t so that the volume of that piece of
%%  the torus is 20.

tSlice = fzero('volDiskLess20', 0.5);
disp([' For problem 3 the volume is 20 when y = ', num2str(tShell) ])