%% 253 demo: graphing the hyperbolic paraboloid
% 2015 W1: Colin Macdonald, public domain

figure(1); clf;
lw = 'linewidth';

% sets of points for x and y
x = linspace(-2, 2, 40);
y = linspace(-2, 2, 40);

plot3(0*y, y, y.^2, 'k-', lw, 3)

grid on
hold on
xlabel('x'); ylabel('y'); zlabel('z')

pause

plot3(x, 0*x, -x.^2, 'b-', lw, 3)

pause

plot3(x,  sqrt(1+x.^2), ones(size(x)), 'r-', lw, 3)
plot3(x, -sqrt(1+x.^2), ones(size(x)), 'r-', lw, 3)

pause

plot3( sqrt(1+y.^2), y, -ones(size(y)), 'm-', lw, 3)
plot3(-sqrt(1+y.^2), y, -ones(size(y)), 'm-', lw, 3)

pause

plot3(x, x, 0*x, 'g-', lw, 3)
plot3(x, -x, 0*x, 'g-', lw, 3)


pause

%% now we add a colourful 3D plot
% meshgrid makes a 2D grid of (x,y) points
[xx, yy] = meshgrid(x, y);
surf(xx, yy, yy.^2 - xx.^2);

axis equal

% add some extra hyperbolas
plot3(x,  sqrt(2+x.^2), 2*ones(size(x)), 'r--', lw, 3)
plot3(x, -sqrt(2+x.^2), 2*ones(size(x)), 'r--', lw, 3)

plot3( sqrt(2+y.^2), y, -2*ones(size(y)), 'm--', lw, 3)
plot3(-sqrt(2+y.^2), y, -2*ones(size(y)), 'm--', lw, 3)

%% other options:
%shading interp
%camlight left
