% 22.3MB1 Fall 01
% Yvan Petillot
% Gradient of a scalar field

close all; clear;
x = -2:.2:2; y = -1:.2:1;    
[xx,yy] = meshgrid(x,y);     
s = xx.*exp(-xx.^2-yy.^2);
figure(1);surf(x,y,s);shading interp;
rotate3d;
xlabel('x');ylabel('y');zlabel('s');
title('2-D space varying scalar field: s = x e^{-(x^2+y^2)}');
pause;
 
[px,py] = gradient(s,.2,.2);
figure(2);quiver(x,y,px,py,2);
xlabel('x');ylabel('y');
title('Gradient of the scalar field: \nablas=(1-2x^2)e^{-(x^2+y^2)} {\bf x} - 2xye^{-(x^2+y^2)} {\bf y}');

