Study the behavior electric potential of an electric dipole
Solution
Below is the matlab code:
dipole.m:
%--Contour diagram of electric dipole potential field
% Matlab code.
close all; clear all
%--Preparing the figure properties
axis([-6 6 -7 7]); axis equal;
xlabel(\'x-axis\', \'Fonts\', 15);
ylabel(\'z-axis\', \'Fonts\', 15);
set(gca, \'fonts\', 16, \'Ytick\', [-6:2: 6] );
hold on;
%--Negative contours are listed here
conto = zeros(9,1);
conto(1) = 0.05;
step = 0.02;
for i=1:9
conto(i+1) = conto(i) + step;
step = step*1.5;
end
conto = -100*conto; conto=round(conto); conto=conto/100;
%--x grid information
x = [-3.5 : .05 : 3.5];
%--Negative z-grid information
z = [-5 : .05 : -.05];
%--Ploting below the x-axis
[X Z] = meshgrid(x,z);
P = Z./(sqrt(X.^2+Z.^2).^3); %<--- Function plotted here
[c h] = contour(X,Z,P, conto, \'b\' );
clabel(c,h, \'manual\', \'fonts\', 12);
%--Flip signs information
z = -z;
conto = -conto;
%--Ploting the above x-axis
[X Z] = meshgrid(x,z);
P = Z./(sqrt(X.^2+Z.^2).^3); %<--- Function plotted here
[c h] = contour(X,Z,P, conto, \'r\');
clabel(c,h, \'manual\', \'fonts\', 12);
