%% electric dipole potential

% charge 1 (negative)
p1 = [-0.995; 0];
q1 = -1;

% charge 2 (positive)
p2 = [0.995; 0];
q2 = 1;

% the grid to compute the potential on
[X, Y] = meshgrid([-2:0.01:2]);

% the electric potential
V = zeros(size(X));
for row = 1:size(X, 1)
    for col = 1:size(X, 2)
        p = [X(row, col); Y(row, col)];
        v1 = q1 / norm(p - p1);
        v2 = q2 / norm(p - p2);
        V(row, col) = v1 + v2;
    end
end

% show the electric potential
c = -1:0.05:1;
contourf(X, Y, V, c)
