%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Team Lab Solution
% Convergence: Volumes of Revolution
% Fall 2004
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Problem 1')

% Part 1.a:  Find area of hemisphere at X = 0;
X = 0;
area0 = areaSphere(X);
disp(['Part 1.a: Area at X = 0 is ', num2str(area0)])

% Part 1.b:  Find volume of entire hemisphere
% first we'll compute it directly using the geometric formula
vol = 0.5 * (4/3*pi*3^3);
disp(['Part 1.b: Volume of entire hemisphere is ', num2str(vol)])
% next we'll compute it using integrals
X = 3;
vol = quad('areaSphere', -3, X);
disp(['          Using integrals, volume is ', num2str(vol)])

% Part 1.c:  Find volume when X = 0
X = 0;
vol = quad('areaSphere', -3, X);
disp(['Part 1.c: When X = ', num2str(X), ' the volume is ', num2str(vol)])


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Problem 2')

% Part 2.a:  Test the area function for t = 1, 2, 3
disp('Part 2.a:')
for t = 1 : 3
    area = areaTorus2(t);
    disp(['   The area at t = ', num2str(t), ' is ', num2str(area)])
end

% Part 2.b:  Use quad to compute the volume for t = 2 and t = 3
disp('Part 2.b:')
vol = quad('areaTorus2', 1, 2);
disp(['   The volume at t = 2 is ', num2str(vol)])
vol = quad('areaTorus2', 1, 3);
disp(['   The volume at t = 3 is ', num2str(vol)])

% Part 2.c:  Set up a function to compute the volume for t = 1, 2, 3
disp('Part 2.c:')
for t = 1 : 3
    vol = volumeTorus2(t);
    disp(['   The volume at t = ', num2str(t), ' is ', num2str(vol)])
end

% Part 2.d:  Find the value of t so that the volume is 20
t = fzero('tobezeroTorus2', 2);
disp(['Part 2.d: The value of t where volume = 20 is ', num2str(t)])


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Problem 3')
t = fzero('tobezeroTorus3', 0.5);
disp(['The value of t where volume = 20 is ', num2str(t)])
