3

How do you plot equipotential electrical field lines on a 2d plot in MATLAB. Would it be best to use either quiver or contourf? Some example points are:

p1 = (1,1) with 1 coulomb charge.

p2 = (2,2) with 2 coulomb charge.

p3 = (3,3) with 3 coulomb charge.

All information I've found online to do with super position only has scenarios for 2 points, and even then I dont really understand the principle behind plotting these values.

Never really done physics before, so this exercise has blind sided me. Thanks for any help!

Firo Proncho
  • 39
  • 1
  • 1
  • 2
  • Are you trying to solve it (1) figuratively, i.e. only describe in words and submit a hand-drawing, or (2) symbolically, to give closed-form equations, or (3) numerically, with MATLAB source code which performs the calculations and plot the results? – rwong May 04 '15 at 23:26
  • 1
    http://hyperphysics.phy-astr.gsu.edu/hbase/electric/mulpoi.html – rwong May 04 '15 at 23:27
  • @rwong I want to do (3) obviously the values I've provided arnt the correct ones, or all of them, Im just looking for some guidance. – Firo Proncho May 05 '15 at 00:06
  • 4
    I'm voting to close this question as off-topic because it is an implementation issue but is too old to migrate. –  Oct 21 '15 at 15:17

1 Answers1

4

This question is ambiguously defined. Electrical field lines (as referenced in the title) are not the same as equipotential lines. Specifically the electric field E followed by electric field lines is related to the electric potential field V by E = −∇V.

In the case of electrical potential, this is a scalar field so equipotential lines are simply contours of constant value of that field. contourf is therefore an ideal choice to visualise this.

As for field lines, quiver will show you the size and direction of vectors in the electric field, but not the field lines. The easiest way to display these in a 2D plane is streamslice.

Calculating and plotting these fields in MATLAB is just a case of setting up the physical equations in a vectorised form and calculating them for a grid of coordinates through which MATLAB can draw contours and field lines.

Using the equation for electrical potential in the form used by rwong's link in the comments above:

Equation for electric potential due to multiple point charges

k = 8.987E9; % Coulomb's constant
p = [1,1; 2,2; 3,3];
Q = [1; 2; 3];
[X,Y] = meshgrid(0:0.05:4); % Create a grid of coordinates where V is to be calculated

V = zeros(size(X)); % Start with zero electric potential
for ii = 1:numel(Q) % Superpose the electric potential field of each charge
    V = V + k * Q(ii) ./ hypot(p(ii,1)-X, p(ii,2)-Y);
end

hContour = contourf(X,Y,V);
hColorbar = colorbar;
ylabel(hColorbar,'Electric potential (V)')

The default contour spacing will be very tightly packed around the point charges due to the singularities in electrical potential they create. If you have the Statistics Toolbox, you can quickly improve on this by finding contour levels with equal area between them using quantile:

hContour.LevelList = [0 quantile(V(:),10)];

The electric field is simpler to derive from the existing potential field than it is from the raw vector equation:

[Ex,Ey] = -gradient(V);
validColumns = all(isfinite(Ex) & isfinite(Ey)); % Ignore columns where E contains infinite values due to the point charges since streamslice can't handle them
hold on
hLines = streamslice(X(:,validColumns),Y(:,validColumns),Ex(:,validColumns),Ey(:,validColumns));
set(hLines,'Color','r');

Resulting contourf figure

Will
  • 148
  • 6