
disp('   Partial Derivatives seen by slices parallel to the x axis ')
disp('   and slices parallel to the y axis  ')
disp(' ')
disp('  You will see the graph of the function ')
disp('    f(x,y) = 2exp(-(x-1)^2 -(y-1)^2) -exp(-2(x+.6)^2 -3(y+.7)^2 ')
disp(' ')
disp('   After you have enlarged the figure window, hit return and' )
disp('   a lower figure window will open with a contour map of the')
disp('   function . You can click 4 times on the lower window to locate')
disp(' where you want to see slices through the graph ')

f = inline('2*exp(-(x-1).^2 -(y-1).^2) -exp(-2*(x+.6).^2-3*(y+.7).^2)', 'x', 'y')
  x = linspace(-2,2, 51);
  y = x;
  [X,Y] = meshgrid(x,y);


 subplot(2,1,1)
   surf(X,Y,f(X,Y)); shading interp; colormap(gray);
   axis([-2 2 -2 2 -2 2])
   hold on
   rotate3d on
 disp(' Rotate the graph in the upper window, enlarge the figure window  ')
 pause
 disp(' ')
 disp(' Now you can click 4 times in the lower window  ')

 subplot(2,1,2)
    levels = linspace(-1,1,21);
    contour(X,Y,f(X,Y),levels)
    hold on
 subplot(2,1,2)
    [p1,p2] = ginput(1);
     plot(p1,p2, '*')
 subplot(2,1,1)
     xedge = [-2 2 2 -2];
     yedge = [p2, p2,p2, p2];
     zedge = [-2 -2 2 2];
     hx = fill3(xedge, yedge, zedge, 'r');
     xedge = [p1,p1, p1, p1];
     yedge = [-2 2 2 -2];
     hy = fill3(xedge, yedge, zedge, 'b');
     % hx = xslice(f, x, p2);
     % hy = yslice(f, p1, y);

 for j = 1:3
     subplot(2,1,2)
        [p1,p2] = ginput(1);
        plot(p1,p2, '*')
     subplot(2,1,1)
        delete(hx); delete(hy);
        % hx = xslice(f,x,p1); 
        % hy = yslice(f,p2,y);
        xedge = [-2 2 2 -2];
        yedge = [p2, p2, p2, p2];
        hx = fill3(xedge, yedge, zedge, 'r');
        xedge = [p1 p1 p1 p1];
        yedge = [-2 2 2 -2];
        hy = fill3(xedge, yedge, zedge, 'b');
  end
  pause
  clf
