# Calculate Electric Potential and Field For Two Charges If we have two electric charges they will generate an electric field. A typical question might be as follows:

We have a charge of +8 nanocoulombs and -4 nanocoulombs placed 60 millimetres apart. What is the electric potential at point P shown below. What is the size and direction of the electric field at point P?

This picture shows the size and position of the charges relative to point P. ## Electric Potential

Starting with the electric potential, it is a scalar which means it has a magnitude but no direction. This makes it easy to calculate. All we need to know is the size of all the charges in the neighbourhood and their distances. Then we add up the potential from each charge. If the distance of a charge from our point P is $$r$$ then for each charge its contribution is

$$V=\frac{q}{4\pi \epsilon_0 r}$$

We have to remember to work in metres, and we can use Pythagoras’ theorem to work out the distances of the two charges. The +8 nC charge on the left is at a distance

$$\sqrt{(80 \times 10^-3)^2+(30 \times 10^-3)^2}=0.08544 \mbox{ m}$$

and the -4 nC charge on the right is at the same distance from P. Now we can work out the electric potential from the +8 nC charge at P,

$$V_{\mbox{+8 nC}} = \frac{8 \times 10^{-9}}{4\pi \epsilon_0 0.08544}=841.5 \mbox{ V}$$

and the contribution of the -4 nC charge is

$$V_{\mbox{-4 nC}} = \frac{-4 \times 10^{-9}}{4\pi \epsilon_0 0.08544}=-420.8 \mbox{ V}$$

and as this is a scalar we can just add the potentials to give

$$V=V_{\mbox{+8 nC}} + V_{\mbox{-4 nC}} = 841.5-420.8 = 420.8 \mbox{ V}$$

If we plot the electric potential it looks like this. The positive charge creates the funnel that sticks up and the negative charge sticks down because its potential is negative. By convention the surface represents the work done, in joules, to drag one coulomb of positive charge from infinitely far away to each point in the 2d region.

## Electric Field

Electric field is more difficult to calculate because it involves adding two vectors. The vectors we add are the fields from the +8 nC and -4 nC charges. The electric field at P is the force that would be felt by a +1 coulomb charge placed at P. Working out the magnitude of the field is easy because the formula for the force between charge $$q_1$$ and $$q_2$$ separated by distance $$r$$ is

$$F=\frac{q_1 q_2}{4\pi \epsilon_0 r^2}$$

We know that when we are calculating the field strength $$q_2$$ is +1 coulombs, so starting with the +8 nC charge the magnitude of the field at P is

$$F_{\mbox{+8 nC}}=\frac{8 \times 10^{-9}}{4\pi \epsilon_0 0.08544^2}=9850 \mbox{ N C}^{-1}$$

Because both charges, the +8 nanocoulomb charge and the “test” charge of +1 coulomb are positive the direction is directly away from the +8 nC charge. The magnitude of the field from the -4 nC charge at P is

$$F_{\mbox{-4 nC}}=\frac{-4 \times 10^{-9}}{4\pi \epsilon_0 0.08544^2}=4925 \mbox{ N C}^{-1}$$

and the direction of this field is directly towards the -4 nC charge because the “test” charge of +1 coulomb and the -4 nC charge are opposite so the force between them is attractive.

To work out the direction of the force a diagram helps. The two fields acting at P are shown in red for the 8 nC charge and blue for the -4 nC charge. To add the fields we simply lay them end-to-end. The resultant field is shown in green. To calculate the components of this field we can decompose the two forces into x and y components and add them. The angle the blue arrow is making with the vertical is

$$\tan^{-1} \left( \frac{30}{80} \right) = 20.6 \mbox{ degrees}$$

The vertical component of the blue field is $$4925 \cos 20.6$$ and the vertical component of the red field is $$-9850 \cos 20.6$$ which adds up to give a vertical component of

$$F_{v} = 4925 \cos 20.6 = 4610 \mbox{ N C}^{-1}$$

The horizontal components of the two fields are in the same direction (toward the right) so they add

$$F_{h} = 4925 \sin 20.6 + 9850 \sin 20.6 = 5198 \mbox{ N C}^{-1}$$

The magnitude of this force is easy to calculate now we know its horizontal and vertical components using Pythagoras again

$$F = \sqrt{F_h^2 + F_v^2} = \sqrt{4610^2 + 5198^2} = 6948 \mbox{ N C}^{-1}$$

This makes an angle 41.6 degrees below the horizontal

$$\tan^{-1} \left( \frac{4610}{5198} \right) = 41.6 \mbox{ degrees}$$

The field at each point is the gradient of the potential. If we ignore magnitude and simply look at the direction of the field at each point it looks like this. Because the convention is that the field is the force on a positive 1 coulomb charge it points away from the positive charge on the left and towards the negative charge on the right.

Fields and potential are always related in this way: field is the gradient of the potential. This is true for electric or gravitational potentials and forces. This is why the lines of equal potential (the contours) are always exactly at right angles with the force vectors.

## Want One-To-One Tuition?

If you found this explanation helpful and you want interactive one-to-one tuition then click on the button. It’s easy to book an hour and I can do online lessons too so you can learn from anywhere.

## R Code

If you want to learn a bit of R and generate the cool interactive 3d visualisation of the potential here’s the code you need.

rm(list=ls())

mp <- 10000 # maximum potential avoids huge potential when r close to zero
two.positive.charges <- function (x, y) {
r1 <- sqrt((x+30e-3)^2+(y-80e-3)^2) # +8 nC charge at position x = -30 mm, y = +80 mm
r2 <- sqrt((x-30e-3)^2+(y-80e-3)^2) # -4 nC charge at position x = +30 mm, y = +80 mm
epsilon0 <- 8.854e-12
p1 <- 8e-9/(4*pi*epsilon0)/r1   # potential from +8 nC charge
p2 <- -4e-9/(4*pi*epsilon0)/r2  # potential from -4 nC charge
# truncate potential when it exceeds mp (huge positive or negative values)
p1 <- pmin(p1,mp)
p1 <- pmax(p1,-mp)
p2 <- pmin(p2,mp)
p2 <- pmax(p2,-mp)
return (p1+p2)
}

# define a grid for the problem from -100 mm to +100 mm in x and from 0 to 200 mm in y
# the point P in the question is at the origin
x <- seq(-100e-3,100e-3,1e-3)
y <- seq(0,200e-3,1e-3)
grid <- expand.grid(x=x,y=y) # create an x-y grid with all combinations of x and y
# outer calculates the potential at all x and y points in the grid
# result stored in a data frame
potential <- data.frame(x=grid$x ,y=grid$y
,potential=as.vector(outer(x,y,two.positive.charges)))

# work out the maximum and minimum potential values
plim <- range(potential$potential) plen <- plim - plim + 1 # build colour map based on range of potential, choose whichever you like best colorlut <- terrain.colors(plen) # height color lookup table colorlut <- heat.colors(plen) # height color lookup table colorlut <- rev(rainbow(plen)) # height color lookup table - we use this one col <- colorlut[ potential$potential - plim + 1 ] # assign colors to heights for each point

library(rgl)
persp(x,y,outer(x,y,two.positive.charges),col=col)   # 3d mesh plot of potential
persp3d(x,y,outer(x,y,two.positive.charges),col=col) # interactive 3d plot in a new window

library(ggplot2)
library(reshape)

# omit tails
max.p <- as.numeric(quantile(potential$potential,probs = c(0.99))) # chop off anything above 99th percentile min.p <- as.numeric(quantile(potential$potential,probs = c(0.01))) # or below the 1st percentile
potential <- potential[potential$potential > min.p,] potential <- potential[potential$potential < max.p,]

library(RColorBrewer)
cols <- brewer.pal(n = 10, name = "RdBu")

library(scales)
max.abs.potential <- max(abs(potential$potential)) g <- ggplot(potential, aes(x=x, y=y, z=potential)) + stat_contour(geom = "polygon", aes(fill = ..level..)) + geom_tile(aes(fill = potential)) + scale_fill_gradientn(colours = cols ,values=scales::rescale( c(max.abs.potential ,0 ,-max.abs.potential)) ,limits=c(-max.abs.potential,max.abs.potential)) + stat_contour(bins = 15) + xlab("x") + ylab("y") + guides(fill = guide_colorbar(title = "Electric Potential (volts)")) + theme_classic() + theme(legend.position="none") # define a coarse grid & potential for the arrows x <- seq(-100e-3,100e-3,10e-3) y <- seq(0,200e-3,10e-3) coarsegrid <- expand.grid(x=x,y=y) coarsepotential <- data.frame(x=coarsegrid$x
,y=coarsegrid$y ,potential=as.vector(outer(x,y,two.positive.charges))) # omit tails max.p <- as.numeric(quantile(coarsepotential$potential,probs = c(0.99)))
min.p <- as.numeric(quantile(coarsepotential$potential,probs = c(0.01))) coarsepotential <- coarsepotential[coarsepotential$potential > min.p,]
coarsepotential <- coarsepotential[coarsepotential\$potential < max.p,]

# calculate field by jiggling points and working out the gradient
dx <- 1e-6
dy <- 1e-6
for (i.row in 1:nrow(coarsepotential)) {
x <- coarsepotential[i.row,"x"]
y <- coarsepotential[i.row,"y"]
# x up-jiggle potential minus x down-jiggle divided by jiggle size is dV / dx
coarsepotential[i.row,"dVdx"] <- (two.positive.charges(x+dx/2,y) - two.positive.charges(x-dx/2,y)) / dx
# y up-jiggle potential minus y down-jiggle divided by jiggle size is dV / dy
coarsepotential[i.row,"dVdy"] <- (two.positive.charges(x,y+dy/2) - two.positive.charges(x,y-dy/2)) / dy
# scale all the field arrows to have length one
scale <- sqrt(coarsepotential[i.row,"dVdx"]^2+coarsepotential[i.row,"dVdy"]^2)
coarsepotential[i.row,"dVdx"] <- coarsepotential[i.row,"dVdx"] / scale
coarsepotential[i.row,"dVdy"] <- coarsepotential[i.row,"dVdy"] / scale
}

scale <- 0.5e-2 # arrow scaling factor
library(grid)
g + geom_segment(data=coarsepotential
,aes(x=x,y=y,xend=x-dVdx*scale,yend=y-dVdy*scale)
,arrow = arrow(length = unit(0.3,"cm"))
,colour="red")

# Now we answer the question in R...

# What's the potential at point P (the origin)?
two.positive.charges(x=0,y=0) # 420.7743 volts

# what is the magnitude and direction of the field at P?
x <- 0
y <- 0
# field is minus dV/dx because a charge moves down the potential slope like rolling down a hill
# from a region of higher to lower potential
dVdx <- -(two.positive.charges(x+dx/2,y) - two.positive.charges(x-dx/2,y)) / dx # -749.3976
dVdy <- -(two.positive.charges(x,y+dy/2) - two.positive.charges(x,y-dy/2)) / dy # 50.8635
# magnitude of field 6940.813 newtons per coulomb
sqrt(dVdx^2+dVdy^2)
# angle with horizontal -41.63354 degrees i.e. below horizontal pointing to the right
180/pi*atan(dVdy/dVdx) # R works in radians so multiply by 180/pi to convert to degrees

# we can also do it the same way as in the text
(theta <- 180/pi*atan(30/80)) # angle of both field vectors from vertical 20.55605 degrees
# magnitude of force from +8 nC charge
x <- -30e-3
y <- 80e-3
(r <- sqrt(x^2 + y^2)) # 0.08544004 metres
(f8 <- 8e-9/(4*pi*8.854e-12*r^2)) # 9849.581 newtons per coulomb field strength for +8 nC charge
# magnitude of force from -4 nC charge
x <- 30e-3
y <- 80e-3
(r <- sqrt(x^2 + y^2)) # 0.08544004 metres, same as other charge thanks to symmetry
(f4 <- -4e-9/(4*pi*8.854e-12*r^2)) # 4924.79 newtons per coulomb field strength for +8 nC charge

# add components in horizontal and vertical directions
(fv <- f4*cos(theta*pi/180) + f8*cos(theta*pi/180)) # 4611.225 newtons per coulomb
(fh <- f4*sin(-theta*pi/180) + f8*sin(theta*pi/180)) # 9849.581 newtons per coulomb

# magnitude of field 6940.813 newtons per coulomb
sqrt(fv^2+fh^2)

# direction of field 41.63354 degrees
180/pi*atan(fv/fh)