import numpy as np
import matplotlib.pyplot as plt
#given
a=0.001
delta=0.2
N=5
epsilon=8.854*10**-12
V_m=4*pi*epsilon
z=np.zeros([N,N])
b=np.zeros(N)
for i in range(0,N):
b[i]=V_m
def m_eq_n(d,a):
temp=2*log(((d/2.0)+sqrt((a**2)+((d/2)**2)))/(a))
return temp
def m_less(m,n,d,a):
l_m=abs(d*n-d*m)
d_mn_p=l_m+d/2
d_mn_n=l_m-d/2
temp=log((d_mn_p+(d_mn_p**2+a**2)**(0.5))/(d_mn_n+(d_mn_n**2+a**2)**(0.5)))
return temp
def m_grt(m,n,d,a):
l_m=abs(d*n-d*m)
d_mn_p=l_m+d/2
d_mn_n=l_m-d/2
temp=log(d_mn_p/d_mn_n)
return temp
for i in range(0,N):
for j in range(0,N):
if i==j:
z[i][j]=m_eq_n(delta,a)
elif abs(i-j) <= 2:
z[i][j]=m_less(i,j,delta,a)
else:
z[i][j]=m_grt(i,j,delta,a)
print "The Z-matrix is:"
print z
print "The Vm matrix is:"
print b
a=np.linalg.solve(z,b)
print "Charge distribution:\n"
for i in range(0,N):
print "a%d:"%i,a[i]*10**12,"pC/m"
m=np.linspace(0,1,11)
C=np.zeros(N*2+1)
i=j=0
while j<5 and i<10:
C[i]=a[j]*10**12
C[i+1]=a[j]*10**12
i=i+2
j=j+1
print C
plt.plot(m,C)
plt.xlabel("Length(m)")
plt.ylabel("Charge Density(pC/m)")
plt.axis([0.0,1.0,7,10])
plt.show()