Newer
Older
from integrator import RombergIntegrator as integral
import math
def d_field(rx,ry,rz,Q):
den = rx**2 + ry**2 + rz**2
if den == 0:
return 0
return Q * rz / math.pow(den, 1.5)
def I_x(x, ry, rz, Q, L):
def ix(rx):
return d_field(rx,ry,rz,Q)
return integral(ix, x-L, x+L, precision = 1e-2)
def E_z(x,y,rz, Q = 1, L = 10):
def iy(ry):
return I_x(x,ry,rz,Q,L)
return integral(iy,y-L, y+L, precision = 1e-2)
def V(x,y, z0 = 1, Q = 1, L = 10):
def vz(rz):
return 2*E_z(x,y,rz,Q, L)
return integral(vz,0,2*z0,precision = 1e-2,silent = False)
print("In the center : potential = {} - theory = {}; diff = {:.2f}%".format(potential,theory, 200*(potential-theory)/(potential + theory)))
potential = V(10,10,distance)
print("In the corner : potential = {} - theory = {}; diff = {:.2f}%".format(potential,theory, 200*(potential-theory)/(potential + theory)))