0

Here is a code simulating the Electric Potential around two oppositely charged particles:

clc; clear; close all;

e_0 = 8.987E-9;                             % Coulomb's constant
xy = [1,2.5; 4,2.5];                        % particle coordinates.
q = [1; -1];                                % particle charge.

sBeg = 0;
sStep = 0.1;
sEnd = 5;
[X,Y] = meshgrid(sBeg : sStep : sEnd);      % generate a 2D-coordinate grid 

V_E = zeros( size(X) );                     % initialise electric potential field.

for i = 1 : numel(q)                        % add potential fields of each charge

  V_E = V_E + e_0 * q(i) ./ hypot( xy(i,1 ) - X, xy(i, 2) - Y );

end

contourf(X,Y, V_E);
ylabel( colorbar, 'Electric Potenial (V)' )

Result:

enter image description here

The contours are concentrated densely near the positions of the particles, how to "spread them" more evenly, while maintaining the same scale for the axis?

NB:

I've tried:

hc = contourf(X,Y,V_E);

contourLevels = [ 0 quantile( V_E(:), 10 ) ];
hc.LevelList = contourLevels;

from here, but I get the following error:

error: invalid assignment to cs-list outside multiple assignment

What am I doing wrong?

I'm running Octave-4.2.1 on Windows 10.

Ziezi
  • 6,375
  • 3
  • 39
  • 49

1 Answers1

2

V_E seems to have an exponential growth; as such, your best bet to get a 'linear' looking contour image is to plot its logarithm.

I would say that this is a more sensible plot anyway. But if you must report the original magnitudes rather than their logarithms, you could simply then change the 'ticklabels' on the colorbar to reflect the values you want, e.g..

contourf(X,Y, log(V_E));
ylabel( cb = colorbar, 'Electric Potenial (V)' ) # note added 'cb' step
set(cb, 'yticklabel', exp(get(cb, 'ytick')))

Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57