Chapter 4: Electrostatic Fields

Example 4.1, Page number: 107

In [1]:
 
import scipy
from numpy import *

#Variable Declaration

ax=array([1,0,0])                   #Unit vector along x direction
ay=array([0,1,0])                   #Unit vector along y direction
az=array([0,0,1])                   #Unit vector along z direction
Q1=1*10**-3                         #charge 1 at (-1,-1,4) in C
Q2=-2*10**-3                        #charge 2 at (3,2,-1) in C
Q=10*10**-9                         #charge 3 at (0,3,1) in C
P1=array([0,3,1])-array([3,2,-1])   #distance vector from charge 3 to 1
P2=array([0,3,1])-array([-1,-1,4])  #distance vector from charge 3 to 2
e=10**-9/(36*scipy.pi)              #permittivity in Farad/m 

#Calculations

modP1=scipy.sqrt(dot(P1,P1))
modP2=scipy.sqrt(dot(P2,P2))
F1=(Q*Q1)*P1*10**3/(4*scipy.pi*e*modP1**3)  #force on charge 3 by 1 in mN
F2=(Q*Q2)*P2*10**3/(4*scipy.pi*e*modP2**3)  #force on charge 3 by 2 in mN

 #Total force on charge 3
 
Fx=round(dot(F1+F2,ax),3)
Fy=round(dot(F1+F2,ay),3)
Fz=round(dot(F1+F2,az),3)
F=array([Fx,Fy,Fz])         #Total force in mN
E=(10**-6)*(F/Q)            #Electric field in kV/m

#Results  

print 'Total force on charge at (0,3,1) =',F,'in mN'
print 'Electric field at (0,3,1) =',E,'kV/m'
Total force on charge at (0,3,1) = [-6.512 -3.713  7.509] in mN
Electric field at (0,3,1) = [-651.2 -371.3  750.9] kV/m

Example 4.3, Page number: 109

In [2]:
 
import scipy
#Variable Declaration

E=500*10**3      #electric field in V/m
Qm=9*10**-6      #Q/m in C/kg
y=0.8            #distance fallen in m
g=9.8            #acceleration due to gravity in m/s^2

#Calculations

t=scipy.sqrt(2*y/g)   #time taken to fall in seconds
x=Qm*E*t**2/2         #half the separation between particles in m
sep=2*x               #separation between particles in m

#Result

print 'The separation between particles is',round(sep*100,2),'cm'
The separation between particles is 73.47 cm

Example 4.5, Page number: 120

In [10]:
 
import scipy
import scipy.integrate

#Variable Declaration

Eo=10**-9/(36*scipy.pi)       #permittivity of free space
ax=array([1,0,0])             #Unit vector along x direction
ay=array([0,1,0])             #Unit vector along y direction
az=array([0,0,1])             #Unit vector along z direction
q=-1                          #charge in mC

#Calculations

def charge(x,y): 
 return x*y*(x**2+y**2+25)**(1.5)
Q, errq = scipy.integrate.dblquad(lambda y , x: charge(x,y),  #total charge in nC
             0, 1, lambda y: 0, lambda y: 1) 

d=(4*scipy.pi*Eo*(x**2+y**2+25)**(1.5))

def elecx(x,y): 
 return 10**-9*x*y*(x**2+y**2+25)**(1.5)*(-x)/d               #x component of electric field
Ex, errx = scipy.integrate.dblquad(lambda y , x: elecx(x,y),  
             0, 1, lambda y: 0, lambda y: 1) 

def elecy(x,y): 
 return 10**-9*x*y*(x**2+y**2+25)**(1.5)*(-y)/d               #y component of electric field
Ey, erry = scipy.integrate.dblquad(lambda y , x: elecy(x,y),  
             0, 1, lambda y: 0, lambda y: 1) 

def elecz(x,y): 
 return 10**-9*x*y*(5)/(4*scipy.pi*Eo)                        #z component of electric field
Ez, errz = scipy.integrate.dblquad(lambda y , x: elecz(x,y),  
             0, 1, lambda y: 0, lambda y: 1) 

E=array([round(Ex,1),round(Ey,1),round(Ez,2)])                #electric field in V/m

F=q*E   #force in mN    

#Results

print 'Total charge =',round(Q,2),'nC'
print 'Electric field at (0,0,5) =',E,'V/m'
print 'Force experienced by -1mC =',F,'mN'
Total charge = 33.15 nC
Electric field at (0,0,5) = [ -1.5   -1.5   11.25] V/m
Force experienced by -1mC = [  1.5    1.5  -11.25] mN

Example 4.6, Page number: 121

In [2]:
 
import scipy
from numpy import *

#Variable Declaration

ax=array([1,0,0])                   #Unit vector along x direction
ay=array([0,1,0])                   #Unit vector along y direction
az=array([0,0,1])                   #Unit vector along z direction
ps1=10*10**-9                       #Surface charge density of plane 1
ps2=15*10**-9                       #Surface charge density of plane 2
pl=10*scipy.pi*10**-9               #charge density of line
e=(10**-9)/(36*scipy.pi)            #permittivity of free space in Farad/m

#Calculations

E1=(ps1/(2*e))*-ax/scipy.pi     #field due to plane 1 in multiples of pi in V/m
E2=(ps2/(2*e))*ay/scipy.pi      #field due to plane 2 in multiples of pi in V/m

 #field due to line charge in multiples of pi in V/m
 
a=(ax-3*az) 
moda=scipy.sqrt(dot((ax-3*az),(ax-3*az)))
e3=(pl/(2*scipy.pi*e*moda**2))*a
E3=array([dot(e3,ax)/scipy.pi,0,dot(e3,az)/scipy.pi])

 #total field in multiples of pi in V/m
 
E=E1+E2+E3      

#Result

print 'The total electric field at (1,1,-1) =',E,'Pi V/m'
The total electric field at (1,1,-1) = [-162.  270.  -54.] Pi V/m

Example 4.7, Page number: 123

In [3]:
 
import scipy
from numpy import *

#Variable Declaration

ax=array([1,0,0])               #Unit vector along x direction
ay=array([0,1,0])               #Unit vector along y direction
az=array([0,0,1])               #Unit vector along z direction
Q=-5*scipy.pi*10**-3            #charge at (4,0,0) in C
pl=3*scipy.pi*10**-3            #charge density of line charge in C/m
r=array([4,0,3])                #point where D is to be found 
rp=array([4,0,0])               #position of point charge

#Calculations 

R=r-rp 
modR=scipy.sqrt(dot(R,R)) 
Dq=(Q*R)/(4*scipy.pi*modR**3)    #flux density due to point charge in C/m^2
p=scipy.sqrt(dot(r,r))
ap=r/p 
Dl=(pl/(2*scipy.pi*p))*ap        #flux density due to line charge in C/m^2
D=(Dq+Dl)*10**6                  #total flux density in micro C/m^2
Dz=round(dot(D,az),0)
Dx=round(dot(D,ax),0)
Dy=round(dot(D,ay),0)
Dround=array([Dx,Dy,Dz])         #value of D rounded to 0 decimal points

#Result

print 'D at (4,0,0) due to point charge and line charge =',Dround,'micro C/m^2'
D at (4,0,0) due to point charge and line charge = [ 240.    0.   41.] micro C/m^2

Example 4.8, Page number: 130

In [4]:
 

import scipy
from numpy import *
import scipy.integrate
from fractions import Fraction

#Variable Declaration

ap=array([1,0,0])                   #Unit vector along rho direction
aph=array([0,1,0])                  #Unit vector along phi direction
az=array([0,0,1])                   #Unit vector along z direction
point=array([1,scipy.pi/4,3])
p1=0
p2=1
ph1=0
ph2=2*scipy.pi

#Calculations

pointp=dot(point,ap)
pointph=dot(point,aph)
pv=pointp*scipy.cos(pointph)**2     #charge density at (1,pi/4,3) in C/m^3

def ctop(phi,p): 
 return 2*p**2*(scipy.cos(phi)**2)
psya, erra = scipy.integrate.dblquad(lambda p , phi: ctop(phi,p),    
             ph1, ph2, lambda p: p1, lambda p: p2)

def cbot(phi,p): 
 return 2*p**2*(scipy.cos(phi)**2)
psyb, errb = scipy.integrate.dblquad(lambda p , phi: cbot(phi,p),    
             ph1, ph2, lambda p: p1, lambda p: p2)
             
psy=psya+psyb                               #Charge in C
psyp=psy/scipy.pi                           #Charge in multiples of Pi in C
psyf=Fraction(psyp).limit_denominator(100)  #converting to fraction


#Results

print 'Charge density at (1,pi/4,3) =',pv,'C/m^3'
print 'Total charge enclosed by the cylinder =',psyf,'Pi C'
Charge density at (1,pi/4,3) = 0.5 C/m^3
Total charge enclosed by the cylinder = 4/3 Pi C

Example 4.10, Page number: 136

In [5]:
 

import scipy
from numpy import *

#Variable Declaration

Q1=-4                   #charge 1 in micro C
Q2=5                    #charge 2 in micro C
e=10**-9/(36*scipy.pi)  #permittivity of free space in Farad/m 

#Calculations

R1=array([1,0,1])-array([2,-1,3])  #distance vector from (1,0,1) to charge 1
R2=array([1,0,1])-array([0,4,-2])  #distance vector from (1,0,1) to charge 2
modR1=scipy.sqrt(dot(R1,R1))
modR2=scipy.sqrt(dot(R2,R2)) 
V=10**-9*((Q1/modR1)+(Q2/modR2))/(4*scipy.pi*e)  #potential in kV

#Result

print 'The potential at (1, 0, 1) =',round(V,3),'kV'
The potential at (1, 0, 1) = -5.872 kV

Example 4.11, Page number: 136

In [5]:
 
import scipy

#Variable Declaration

Eo=10**-9/(36*scipy.pi)       #permittivity of free space
Vo=0                          #potential at O in V
Vb=100                        #potential at B in V
po=scipy.sqrt(2)
ro=5
pa=1
ra=9
pb=1
rb=scipy.sqrt(21)
pc=scipy.sqrt(20)
rc=scipy.sqrt(11)
pl=2*10**-9                   #charge density of the line in C/m
Q=5*10**-9                    #point charge at (-3,4,0) in C

#Calculations

Va=Vo-(-pl*scipy.log(po/pa)/(2*scipy.pi*Eo)+Q*(ra-ro)/(4*scipy.pi*Eo*ra*ro))
Vc=Vb+(-pl*scipy.log(pc/pb)/(2*scipy.pi*Eo)+Q*(rb-rc)/(4*scipy.pi*Eo*rb*rc))
Vbc=Vc-Vb

#Results

print 'Va =',round(Va,3),'V'
print 'Vc =',round(Vc,3),'V'
print 'Vbc =',round(Vbc,3),'V'
Va = 8.477 V
Vc = 49.825 V
Vbc = -50.175 V

Example 4.12, Page number: 140

In [6]:
 

import scipy
from numpy import *

#Variable Declaration

ar=array([1,0,0])                   #Unit vector along radial direction
ath=array([0,1,0])                  #Unit vector along theta direction
aph=array([0,0,1])                  #Unit vector along phi direction
e=(10**-9)/(36*scipy.pi)            #permittivity of free space in Farad/m

 #The point (2, pi/2, 0)
r=2
th=scipy.pi/2
ph=0
 #Point A
ra=1
tha=scipy.pi*30/180
pha=scipy.pi*120/180
 #Point B
rb=4
thb=scipy.pi/2
phb=scipy.pi*60/180

q=10*10**-6 

#Calculations

Er=(20.0/r**3)*scipy.sin(th)*scipy.cos(ph)   #Radial component of E in V/m
Eth=-(10/r**3)*scipy.cos(th)*scipy.cos(ph)   #Theta component of E in V/m
Eph=(10/r**3)*scipy.sin(ph)                  #Phi component of E in V/m
E=array([Er,Eth,Eph])
D=E*e*10**12              #Electric flux density D in pC/m^2
Dr=round(dot(D,ar),1)     #Radial component of D in V/m rounded to 1 decimal
Dth=round(dot(D,ath),0)   #Theta component of D in pC/m^2 rounded to 0 decimal
Dph=round(dot(D,aph),0)   #Phi component of D in pC/m^2 rounded to 0 decimal
Dc=array([Dr,Dth,Dph])    #Rounded D in pC/m^2

Va=10*scipy.sin(tha)*cos(pha)/ra**2    #potential at point A in V
Vb=10*scipy.sin(thb)*cos(phb)/rb**2    #potential at point B in V
W=q*(Vb-Va)*10**6                      #work done in micro J

#Results

print 'The electric flux density D at (2, pi/2, 0) =',Dc,'pC/m^2'
print 'Work done in moving the charge =',W,'micro J'
The electric flux density D at (2, pi/2, 0) = [ 22.1  -0.    0. ] pC/m^2
Work done in moving the charge = 28.125 micro J

Example 4.13, Page number: 145

In [7]:
 

import scipy
from numpy import *

#Variable Declaration

p1=-5*10**-9               #dipole moment of dipole 1 in C/m
p2=9*10**-9                #dipole moment of dipole 2 in C/m
z1=2                       #z component of position vector of dipole 1
z2=-3                      #z component of position vector of dipole 2
e=10**-9/(36*scipy.pi)     #permittivity of free space in Farad/m

#Calculation

V=(1/(4*scipy.pi*e))*((p1*abs(z1)/z1**3)+(p2*abs(z2)/z2**3))

#Result

print 'Potential at origin =',V, 'V'
Potential at origin = -20.25 V

Example 4.14, Page number: 148

In [8]:
 
import scipy
from numpy import *

#Variable Declaration

Q1=-1*10**-9            #Charge 1 in C
Q2=4*10**-9             #Charge 2 in C
Q3=3*10**-9             #Charge 3 in C
e=10**-9/(36*scipy.pi)  #permittivity of free space in farad/m

#Calculations

V1=(1/(4*scipy.pi*e)*(Q2+Q3))
V2=(1/(4*scipy.pi*e)*(Q1+Q3/(2**.5)))
V3=(1/(4*scipy.pi*e)*(Q1+Q2/(2**.5)))
W=0.5*((V1*Q1)+(V2*Q2)+(V3*Q3))*10**9  #Energy in nJ

#Result

print 'Energy in the system =',round(W,2),'nJ'
Energy in the system = 13.37 nJ