function dipole
% Contour plot of dipole potential in first quadrant, plus quiver 
% plot of field direction.  Dipole is oriented along y axis.
x = .05:.05:1; % 20 points along x axis 
y = x;
[X,Y] = meshgrid(x,y); % set up x-matrix and y-matrix
R = sqrt(X.^2 + Y.^2); % length of radius vector
fi = Y./R.^3;          % dipole potential 
ex = 3.*X.*Y./R.^5;    % corresponding field component
ey = (2.*Y.^2 - X.^2)./R.^5;
ea = sqrt(ex.^2 + ey.^2); % absolute value of field
nx = ex./ea;           % x-component of unit vector
ny = ey./ea;           % y-component of unit vector
% plot log(fi), not fi, to show potential far from the origin
contour(x,y,log(fi))
hold on  % plot potential and field direction together
quiver(X,Y,nx,ny)
hold off
pause
quiver(X,Y,ex,ey)      % show the uselessness of field plot
return

