
clear
close all
disp('              GRAPHS AND LEVEL CURVES ')

disp(' f(x,y) = 2*exp(-(x-1)^2 -(y-1)^2) - exp(-2*(x+.3)^2 -3*(y+.5)^2) ')

f1 = '2*exp(-(x-1).^2 -(y-1).^2)';
f2 = '-exp(-2*(x+.3).^2 -3*(y+.5).^2)';
f = inline([f1,f2], 'x', 'y');
 disp(' ')
 disp(' First we graph the function. The graph has one hill and one')
 disp(' valley ')
x = linspace(-2,2, 51);
y = x;
[X,Y] = meshgrid(x,y);
surf(X,Y,f(X,Y)); shading interp;
view(45, 50)
pause

disp(' ')
disp(' Now we graph the contour lines in xyz space ')
figure
levels = linspace(-.9, 2, 21);
contour3(X,Y,f(X,Y), levels)
view(45,50)
rotate3d on
pause

disp(' ')
disp(' When we project the contour lines down into the xy plane ')
disp(' we get the level curves   ')
contour(X,Y,f(X,Y), levels)
pause
close all

disp(' ')
disp(' g(x,y) =  sin(x+y) +1 -x^2/40 + exp(-y^2)  ')

g = inline(' sin(x+y) +1 -x.^2/40 + exp(-y.^2)', 'x', 'y');
disp(' ')
disp('First we graph g. The graph has a number of ripples ')
clear x y
x = linspace( -3,3, 51);
y = x;
[X,Y] = meshgrid(x,y);
surf(X,Y,g(X,Y)); shading interp;
view(20,50)
pause

disp('   The contour lines in xyz space ')
figure
contour3(X,Y,g(X,Y))
view(20,50)
rotate3d on
pause



disp(' ')
disp(' Then we display the level curves  ')
contour(X,Y,g(X,Y))
pause
close all
