EM ASSIGNMENT: More on Electric field from Continuous Distribution Franck KALALA M. November 30, 2006 1.Computation of the electric field Figure 1: vector representation of the problem let first study analytically the problem before to write a program to compute the electric of thin uniformly → − charged rod. Let assume the thin rod as a set of continuous charge dq,and call d E the electric field due to the charge dq at the distance r. According the principle of superposition, The total electric field of th rod will be → − the sum of the contribution of each charge at the point on which we want to evaluate the field. we define d E by the formula → − dE = → 1 dq − r → 2 4πε0 r |− r| (1) Looking at the figure below we have: 0 − → → → r +− r =− x Then 0 → − → → r =− r −− r p 0 → − → − → − → r = r − r = (x0 , y0 − y, z0 ) and |− r | = x20 + (y − y0 )2 + z02 So → − dq (x0 , y0 − y, z0 ) dE = 4πε0 (x20 + (y0 − y)2 + z02 ) 23 (2) Let dy be the length of the piece that represents the charge the charge dq, we by definition of the linear distribution of the charge the following relation: Q dq = L dy Where Q is the total charge of the rod and L is length. so the dq = L to integrate the vector relation (2) from −L 2 to 2 and we have: Z Ex = L 2 −L 2 (3) Qdy L . dq x0 dy 2 4πε0 (x0 + (y0 − y)2 + z02 ) 23 1 To find the total charge we have (4) Z Ey = −L 2 Z Ez = L 2 L 2 −L 2 dq (y0 − y)dy 2 4πε0 (x0 + (y0 − y)2 + z02 ) 23 (5) dq z0 dy 4πε0 (x20 + (y0 − y)2 + z02 ) 23 (6) → − − → → − → − E = Eq x i + E y j + Ez k → − | E | = Ex2 + Ey2 + Ez2 The formula are the analytic expression of the integral needed to evaluate the components of the electric field at the point (x0 , y0 , z0 ). Those integral are not easy to evaluate. We will use the numerical method of the integration in python, with the Scipy module by using the integrate sub-package. We have used the function quad (quadrature) of that sub-package to evaluate those integral. The function return a couple, the first element of the couple is the value of the finite integral and the second component is the error. This is our program that computes the electric field of a charge rod. ****************************************************************************************** #program 1 #This program evaluate the electric field of a charge rod at location around the rod. from __future__ import division from scipy import * from scipy.integrate import quad from math import * import Gnuplot q=1e-8 L=1 K=9e9 #print list def rodfield(): list=input(’in which point to evaluate the field?[x,y,z]\n’) #Evaluate the first component of the vector field E Ex=quad(lambda t:(K*q/L)*list[0]/(list[0]**2+(t-list[1])**2+list[2]**2)**1.5,-L/2,L/2) #Evaluate the second component of the vector field E Ey=quad(lambda t:(K*q/L)*(list[1]-t)/(list[0]**2+(t-list[1])**2+list[2]**2)**1.5,-L/2,L/2) #Evaluate the third component of the vector field E Ez=quad(lambda t:(K*q/L)*list[2]/(list[0]**2+(t-list[1])**2+list[2]**2)**1.5,-L/2,L/2) #compute the magnitude of the vector field E E=sqrt(Ex[0]**2+Ey[0]**2+Ez[0]**2) #print the magnitude of the vector field E print E rodfield() z=input(’continue?y/n\n’) if z==’y’: rodfield() else: print ’thank you guy’ ************************************************************************************************ In space we have the following program which display the electric field the rod (fig. 2) ************************************************************************************************ #program 2 #this program computes the electric field of a charge rod and #display the electric field of a charge rod in three dimesion. see figure 2 from __future__ import division from visual import * from scipy import * from scipy.integrate import quad d = 6.0 #adjust length of axes as needed r = d*0.002 # thickness of axes L=1 K=9e9 Escale =1e-3 2 q=1e-8 scene.background=color.white #this makes it easier to see when projected scene.x=scene.y=0 scene.width=1000 scene.height=1000 #xaxis=cylinder(pos=vector(0,0,0),axis=vector(d,0,0),radius=r) #yaxis=cylinder(pos=vector(0,0,0),axis=vector(0,d,0),radius=r) #zaxis=cylinder(pos=vector(0,0,0),axis=vector(0,0,d),radius=r) ## #label(pos=xaxis.pos+xaxis.axis,text=’x’,box=0) #label(pos=yaxis.pos+yaxis.axis,text=’y’,box=0) #label(pos=zaxis.pos+zaxis.axis,text=’z’,box=0) scene.forward = (-0.2,-0.2,-1) #rod=cylinder(pos=(0,-L/2,0),axis=(0,L,0),radius=0.005,color=color.blue) #def rodfield(): for x in arange(-1.2,1.2,0.7): for y in arange(-1.2,1.2,0.7): for z in arange(-1,1.2,0.7): l=[x,y,z] #l=input(’in which point to evaluate the field?[x,y,z]\n’) #Evaluate the first component of the vector field E E1=quad(lambda t:(K*q/L)*l[0]/(l[0]**2+(t-l[1])**2+l[2]**2)**1.5,-L/2,L/2) #Evaluate the second component of the vector field E E2=quad(lambda t:(K*q/L)*(l[1]-t)/(l[0]**2+(t-l[1])**2+l[2]**2)**1.5,-L/2,L/2) #Evaluate the third component of the vector field E E3=quad(lambda t:(K*q/L)*l[2]/(l[0]**2+(t-l[1])**2+l[2]**2)**1.5,-L/2,L/2) #compute the magnetude of the vector field E E=sqrt(E1[0]**2+E2[0]**2+E3[0]**2) Ep=vector(E1[0],E2[0],E3[0]) rod=cylinder(pos=(0,-L/2,0),axis=(0,L,0),radius=0.01,color=color.black) ar = arrow(pos=(x,y,z), color=color.red, axis=Escale*Ep, shaftwidth=0.2) #print the vector field Ep print Ep #print the magnitude of the vector Ep print mag(Ep) *************************************************************************************************** And the electric field looks like this: 2. Modelling of the rod. Let consider the rod formed by a collection of N point charges, each with charge Q/N Coulomb. The electric field of the rod on a given point will the sum of the electric field of each element constituting the rod. We choose to model the rod by small sphere. When we increase the number of sphere we found approximately the rod. So we have to compute the electric field of each sphere, add them and find the approximation of the field. We have to define a list of N charge point which will be called thinrod, because that is what it is going to approximate. We make an empty list than can be filled with points. Each segment of the rod of the length dl will be approximated by a point at is at middle. The y value for the middle of the lowest segment is -(L/2)+(dL/2). The function arange can be used to make a list of y-values like this : charges− y− val = arange(−(L/2) + (dL/2), (L/2), dL) We have to make a for loop where y loops over the value in the list charges− y− val. Inside the loop, create a sphere to represent each point and add it to the list thinrod by the two vpython command: sp=sphere(pos(0,y,0), color=color.red, radius=.0011, charge=Q/N) append thinrod(sp) Where pos=(0,y,0) specify the position of the point− shepre, color.red is the colour of the point,radius and the charge of the point. The criterion used to make decision to consider the rod as a collection of N point charge, is that: In most of cases it is difficult to evaluate the analytic expression needed to find the electric field. As the rod is 3 Figure 2: electric field in space of a charge thin rod continuous we can divide it into small pieces and find the contribution of each pieces. By taking a large number of point and add the contribution of each we expect to find the correct answer. Below there is the program used to model the rod and to display the electric field around it. This model is accurate when we increase the number of point. #Program 3 #this program model in the charge rod as a collection of points and #Evaluate the electric field and display it. This display is very similar #to the display of the exact electric field (fig.2). See figure 2, at the end of the document. from __future__ import division from visual import * from scipy import * from scipy.integrate import quad d = 6.0 #adjust length of axes as needed r = d*0.002 # thickness of axes L=1 K=9e9 N=50 Escale =1e-3 Q=1e-8 dl=L/N scene.background=color.white #this makes it easier to see when projected scene.x=scene.y=0 scene.width=1000 scene.height=1000 scene.forward = (-0.2,-0.2,-1) 4 ## thinrod=[] for y in arange((-L/2.)+(dl/2.),(L/2.),dl): # we modelize our rod as a set of sphere charge point sp=sphere(pos=(0,y,0),color=color.red,radius=0.01,q=Q/N) # let add each sphere point in the list thinrod thinrod.append(sp) # let calculate the points on which we need to evaluate the electric field location=[] for x in arange(-1.2,1.2,0.7): for y in arange(-1.2,1.2,0.7): for z in arange(-1,1.2,0.7): pt=vector(x,y,z) location.append(pt) # for each point in location, let evaluate the electric field of each point, #and add them to have the electric field of the model of the rod at each point for pt in location: E=vector(0,0,0) for charge in thinrod: #vector position from the charge point to the point on which we to e #evaluate the fied r=pt-charge.pos #we evaluate the magnetude of the electric field at the corresponding #point E=E+norm(r)*K*charge.q/mag(r)**2 print E #we plot an arrow, at the correponding point in the direction of the vector field ar=arrow(pos=pt,color=color.green,axis=Escale*E,shaftwidth=0.2) 3.Display of the electric field By using the Program (which model the rod) we have the following display: I want to mention something which is very important. The display of the electric field of the rod as collection of point (figure 3) looks very similar to display of the exact electric field of the charge rod (figure 2) without modelling. Also the magnitude of the electric field find at the point (1,1,1) when using the program 1 or 2 gives the value of 31.549. The value find when we use the program 3 which model the charge rod as a collection of points (N=50) is 30.456 which is very close to the exact value. By increasing the number of point; for example N=100 or more we find a value which is close and close to the really value. So we can use this model to approximate the electric field of the charge rod and plot it. (see the next page ) ----------------------------------------------------This is a comparison between the electric field find when we use the program 2(for continuous rod) and the program 3 (which model the charge rod,N=50). points result (program2) result (program3) electric field electric field (1,2,1) 15.310 15.309 (0,0,1) 80.501 80.498 (-1,0,0) 80.501 80.498 (-1.2,1.2,1.2) 20.815 20.814 ----------------------------------------------------The results in the two cases are very closed, hence our model is accurate. 5 Figure 3: electric field of a charge rod as a collection of points 5 4 3 2 1 0 -1 -2 -3 -4 -5 -10 -8 -6 -4 -2 0 2 4 6 Figure 4: electric field of a charge rod in the plan 6 8 10
© Copyright 2026 Paperzz