% % illustrates the gradient % [x, y] = meshgrid([-3:0.1:3]); [u, v] = meshgrid([-3:0.5:3]); z = exp(-0.5*(x.^2 + y.^2)); w = exp(-0.5*(u.^2 + v.^2)); [pu, pv] = gradient(w, .1, .1); figure; subplot(121); surfc(x, y, z); subplot(122); contour(x, y, z); hold on; quiver(u, v, pu, pv); axis image;