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:
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.