% ShowContour

% Using contour to display the curves 

% Suppose we want to display in a single window the
% ellipse 3x^2 + 2y^2 = 1 and the hyperbola 2x^2 - 4y^2 = 3
% This means that we should display the zero level sets of
%
%     f(x,y) =  3x^2 + 2y^2 - 1
%     g(x,y) =  2x^2 - 4y^2 - 3
%
% Here is how to do this..

% Determine the x and y ranges and the sample points within
a = -3; b = 3; c = -2 ; d = 2; m = 100; n = 100;
x = linspace(a,b,n);
y = linspace(c,d,m);

% Set up the matrices of function evaluations
Zf = zeros(m,n);
Zg = zeros(m,n);
for i = 1:m
    for j=1:n
       Zf(i,j) = 3*x(j)^2 + 2*y(i)^2 - 1;   % Zf(i,j) = f(x(j),y(i))
       Zg(i,j) = 2*x(j)^2 - 4*y(i)^2 - 3;   % Zg(i,j) = g(x(j),y(i))
    end
end

% Display the zero contour lines and also the origin
contour(x,y,Zf,[0 0],'r')
hold on
contour(x,y,Zg,[0 0],'k')
plot(0,0,'*g')
hold off