Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- e0 = 8.85*10**-12 #C^2/Nm^2
- x = 5. #meters
- y = 5. #meters
- z = 8. #meters
- width = 0.001
- dx = numpy.arange(-1,1,width)
- intx = numpy.zeros(dx.size)
- inty = numpy.zeros(dx.size)
- intz = numpy.zeros(dx.size)
- #Calculating Electric Field
- for i in range(dx.size):
- lamb = (6.0*10**-6)*(1-dx[i]**2)
- intx[i] = width*(1./(4.*numpy.pi*e0))*lamb*(x-dx[i])/(((x-dx[i])**2 + y**2 + z**2)**(3./2))
- inty[i] = width*(1./(4.*numpy.pi*e0))*lamb*(y)/(((x-dx[i])**2 + y**2 + z**2)**(3./2))
- intz[i] = width*(1./(4.*numpy.pi*e0))*lamb*(z)/(((x-dx[i])**2 + y**2 + z**2)**(3./2))
- x_sum = numpy.sum(intx)
- y_sum = numpy.sum(inty)
- z_sum = numpy.sum(intz)
- potx = numpy.zeros(dx.size)
- #Calculating Electrostatic Potential
- for i in range(dx.size):
- lamb = (6.0*10**-6)*(1-dx[i]**2)
- potx[i] = width*(1./(4.*numpy.pi*e0))*lamb/(((x-dx[i])**2 + y**2 + z**2)**(1./2))
- potsum = numpy.sum(potx)
- potplus = numpy.zeros(dx.size)
- potminus = numpy.zeros(dx.size)
- dv = 0.001
- #Calculating Electrostatic Potential at small points
- for i in range(dx.size):
- lamb = (6.0*10**-6)*(1-dx[i]**2)
- potplus[i] = width*(1./(4.*numpy.pi*e0))*lamb/((((x+dv)-dx[i])**2 + y**2 + z**2)**(1./2))
- potminus[i] = width*(1./(4.*numpy.pi*e0))*lamb/((((x-dv)-dx[i])**2 + y**2 + z**2)**(1./2))
- Etest = -(numpy.sum(potplus) - numpy.sum(potminus))/(2*dv)
- Error = 100*numpy.abs(x_sum-Etest)/Etest
- print ('Coordinates of E field are '),x_sum,(' x^ ,'),y_sum,(' y^ ,'),z_sum,(' z^')
- print ('Electrostatic potential is '),potsum
- print ('Approximation of Electric Field at X is '),Etest
- print ('Percent error between approximation and actual is '),Error,('%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement