% gradient field demo % author: Fernando Guevara Vasquez x =linspace(-1,1,20); y =linspace(-1,1,20); [xx,yy]=meshgrid(x,y); zz = xx.^2-yy.^2; % plot the surface figure(1); clf; h=mesh(xx,yy,zz); set(h,'edgecolor','k','facecolor','green','facealpha',0.5); % plot the gradient field figure(2); clf; dx=2*xx; dy=-2*yy; contour(xx,yy,zz); hold on; quiver(xx,yy,dx,dy); colorbar