%% Problem Set E: Problem 5, Parts (b) and (c)

clear all; close all

%
%% (b) A hyperbolic paraboloid or saddle surface

syms x y z; h = x^2 - 4*y^2 - z; 
figure; fimplicit3(h, [-1, 1, -1, 1, -1, 1]); axis equal
% A classic saddle surface.

%
% Now for the tangent plane

syms x y real; gradh = jacobian(h)
subs(gradh, [x,y, z], [0,0,0])
% So the normal vector is (0, 0, -1) (or its negative). This verifies 
% that the tangent plane is the x-y plane. Let's add it to the graph.
hold on; fsurf(x, y, 0, [-1 1 -1 1])

%
%% (c) The ellipsoid

syms x y z; h = x^2 + 4*y^2 + 9*z^2; 
figure; fimplicit3(h-1, [-1 1 -0.5 0.5 -1/3 1/3]); axis equal
% Note that the surface looks something like a football.

%
% Now we find the gradient and tangent plane.

syms x y real; gradh = jacobian(h)
subs(gradh, [x,y,z], [1,0,0])
% The tangent plane is thus normal to (2, 0, 0) or  2i, and so is 
% parallel to the y-z plane. The tangent plane is thus x=1.  This is not 
% the graph of a function of two variables, so we display it as a 
% parametric plot of a surface.
hold on; syms u v; fsurf(1, u, v, [-1/2 1/2 -1/3 1/3])