# Homework Help: Using VPython program to calculate the E-field

Tags:
1. Apr 17, 2015

### HaLAA

1. The problem statement, all variables and given/known data
Charge a ring of radius R=5.0cm laying in the x-y plane to 50nC.

Create a VPython program that will allow you to calculate the E-field due to the ring anywhere in space.

2. Relevant equations

E_ring=kQz/(R^2+z^2)^(3/2), point P above the xy-plane

3. The attempt at a solution

from visual import *

C = pi*.10 # meters
Q = 50.0*10**-9 #Coulombs
k = 8.99*10**9 # Nm^2/C^2
E = vector(0.0,0.0,0.0) # N/C

Lambda = Q/C # linear charge density
s=vector(0.025,0.0,0.025)

# we are looking for the E-field due to the ring at anywhere, I think we would have dD,
# but I don't know how to define it.

ds = vector(D/10000,D/10000,D/10000)
dq = mag(Lambda*ds)

while s.x < L+D:

rate=(10000)
dE = k*dq/(mag(s)**2)*norm(s)
E = E + dE
s = s + ds

print 'sx=',s.x,'dE=',dE,'E=',E
print 'E=',E,'N/C'

2. Apr 18, 2015

### robphy

Does your formula for the ring work everywhere? Or just on the axis?

It might better to model ring of charge as a set of equally spaced point charges on the ring.
Then at the point of interest, find the electric-field vector there as a vector sum of electric-field contributions from each point charge.

You can use your formula to check at a point where it is valid.

3. Apr 18, 2015

### HaLAA

The formula only model on the z-axis.

I don't know how to model ring of charge as a set of equally spaced point charges on the ring?

Can you give me a hit?

4. Apr 18, 2015

### robphy

Can you draw the vertices of a regular polygon on a circle?

5. Apr 18, 2015

### HaLAA

I don't know how to draw it.

6. Apr 18, 2015

### robphy

If you had to draw a regular octagon, what angles would use?