You are on page 1of 2

13

%Vector fields with and without sources/sinks


close all; clear;
x = -2:.2:2; y = -1:.2:1;
[xx,yy] = meshgrid(x,y);
v = xx.*exp(-xx.^2-yy.^2);
[ex,ey] = gradient(v,.2,.2);
figure(1);quiver(x,y,ex,ey,2);
xlabel('x');ylabel('y');
title('2-D vector field: {\bf E} =
(1-2x^2)e^{-(x^2+y^2)} {\bf x} 2xye^{-(x^2+y^2)} {\bf y}');
pause;
div_e=del2(v);
figure(2);surf(x,y,div_e);shading
interp;rotate3d;
xlabel('x');ylabel('y');
title('Divergence of 2-D vector field: \nabla
\cdot {\bf E}');
pause;
x = -2:0.2:2; y = -2:0.2:2;
[xx,yy] = meshgrid(x,y);
bx = -yy./(xx.^2+yy.^2);
by = xx./(xx.^2+yy.^2);
figure;quiver(x,y,bx,by);
xlabel('x');ylabel('y');
title('2-D vector field: {\bf B} = -y
/(x^2+y^2){\bf x} + x /(x^2+y^2) {\bf y} ');
pause;
[bxx,bxy]=gradient(bx,0.2,0.2);
Page 1

13
[byx,byy]=gradient(by,0.2,0.2);
div_b=(bxx+byy);
figure;surf(x,y,div_b);shading
interp;rotate3d;
xlabel('x');ylabel('y');
title('Divergence of 2-D vector field: \nabla
\cdot {\bf B}: {\bf Must be Zero!!!}');

Page 2