Background
Abstract
This exercise is about electric potential and fields.Compared with the Eular-Cromer method applied in former exercises, this time we use relaxation method to solve problems linked to Laplace's equation and its generalization.
The Main Body
Laplace's Equation
In order to find the distribution of the electric field of the capacitor, we need to solve for the Laplace's equation. In mathematics, Laplace's equation is a second-order partial differential equation named after Pierre-Simon Laplace who first studied its properties. This is often written as:
or:
Laplace's equation and Poisson's equation are the simplest examples of elliptic partial differential equations. The general theory of solutions to Laplace's equation is known as potential theory. The solutions of Laplace's equation are the harmonic functions, which are important in many fields of science, notably the fields of electromagnetism, astronomy, and fluid dynamics, because they can be used to accurately describe the behavior of electric, gravitational, and fluid potentials. In the study of heat conduction, the Laplace equation is the steady-state heat equation.
The Relaxation method
The method that we use to find the field is relaxation method. In numerical mathematics, relaxation methods are iterative methods for solving systems of equations, including nonlinear systems.
Relaxation methods were developed for solving large sparse linear systems, which arose as finite-difference discretizations of differential equations. They are also used for the solution of linear equations for linear least-squares problems and also for systems of linear inequalities, such as those arising in linear programming. They have also been developed for solving nonlinear systems of equations.
Jacobi Method
In numerical linear algebra, the Jacobi method (or Jacobi iterative method) is an algorithm for determining the solutions of a diagonally dominant system of linear equations. Each diagonal element is solved for, and an approximate value is plugged in. The process is then iterated until it converges. This algorithm is a stripped-down version of the Jacobi transformation method of matrix diagonalization. The method is named after Carl Gustav Jacob Jacobi.
Successive over-relaxation
In numerical linear algebra, the method of successive over-relaxation (SOR) is a variant of the Gauss–Seidel method for solving a linear system of equations, resulting in faster convergence. A similar method can be used for any slowly converging iterative process. It was devised simultaneously by David M. Young, Jr. and by H. Frankel in 1950 for the purpose of automatically solving linear systems on digital computers. Over-relaxation methods had been used before the work of Young and Frankel. An example is the method of Lewis Fry Richardson, and the methods developed by R. V. Southwell. However, these methods were designed for computation by human calculators, and they required some expertise to ensure convergence to the solution which made them inapplicable for programming on digital computers. These aspects are discussed in the thesis of David M. Young, Jr.
We have the following equations:
specially, for two dimensional problem
Jacobi method:
Gauss-Seidel method:
Simultaneous over-relaxation method (SOR method):
The best choice for alpha is:
code
import numpy as np
from pylab import *
from math import *
import mpl_toolkits.mplot3d
global error
error=1e-5
def Jacobi(L):
V0=[[0 for i in range(L)]for j in range(L)]#i represents x, j represents y
a=int(2*(L-1)/5)
b=int(3*(L-1)/5)
for i in [a]:
for j in range(a,b+1):
V0[j][i]=1.0# j,i
for i in [b]:
for j in range(a,b+1):
V0[j][i]=-1.0
VV=[]
VV.append(V0)
s=0
dx=0.1
#iteration
while 1:
VV.append(V0)
for i in range(1,L-1):
for j in range(1,L-1):
VV[s+1][i][j]=(VV[s][i+1][j]+VV[s][i-1][j]+VV[s][i][j+1]+VV[s][i][j-1])/4.0
for i in [a]:
for j in range(a,b+1):
VV[s+1][j][i]=1.0
for i in [b]:
for j in range(a,b+1):
VV[s+1][j][i]=-1.0
VV[s]=np.array(VV[s])
VV[s+1]=np.array(VV[s+1])
dVV=VV[s+1]-VV[s]
dV=0
for i in range(1,L-1):
for j in range(1,L-1):
dV=dV+abs(dVV[i][j])
s=s+1
print dV
if dV<error*(L-1)**2 and s>1:
#if dV<error and s>10:
break
return s
def GS(L):
V0=[[0 for i in range(L)]for j in range(L)]#i represents x, j represents y
a=int(2*(L-1)/5)
b=int(3*(L-1)/5)
for i in [a]:
for j in range(a,b+1):
V0[j][i]=1.0# j,i
for i in [b]:
for j in range(a,b+1):
V0[j][i]=-1.0
VV=[]
VV.append(V0)
s=0
dx=0.1
#iteration
while 1:
VV.append(V0)
for i in range(1,L-1):
for j in range(1,L-1):
VV[s+1][i][j]=(VV[s][i+1][j]+VV[s+1][i-1][j]+VV[s][i][j+1]+VV[s+1][i][j-1])/4.0
for i in [a]:
for j in range(a,b+1):
VV[s+1][j][i]=1.0
for i in [b]:
for j in range(a,b+1):
VV[s+1][j][i]=-1.0
VV[s]=np.array(VV[s])
VV[s+1]=np.array(VV[s+1])
dVV=VV[s+1]-VV[s]
dV=0
for i in range(1,L-1):
for j in range(1,L-1):
dV=dV+abs(dVV[i][j])
s=s+1
if dV<error*(L-1)**2 and s>1:
#if dV<error and s>1:
break
return s
def SOR(L):
a=int(2*(L-1)/5)
b=int(3*(L-1)/5)
V0=[[0 for i in range(L)]for j in range(L)]#i represents x, j represents y
for i in [a]:
for j in range(a,b+1):
V0[j][i]=1.0# j,i
for i in [b]:
for j in range(a,b+1):
V0[j][i]=-1.0
VV=[]
VV.append(V0)
alpha=2.0/(1+pi/L)
s=0
dx=0.1
#iteration
while 1:
VV.append(V0)
for i in range(1,L-1):
for j in range(1,L-1):
VV[s+1][j][i]=(VV[s][j+1][i]+VV[s+1][j-1][i]+VV[s][j][i+1]+VV[s+1][j][i-1])/4.0
if i==a and j>a-1 and j<b+1:
VV[s+1][j][i]=1.0
if i==b and j>a-1 and j<b+1:
VV[s+1][j][i]=-1.0
VV[s+1][j][i]=alpha*(VV[s+1][j][i]-VV[s][j][i])+VV[s][j][i]
VV[s]=np.array(VV[s])
VV[s+1]=np.array(VV[s+1])
dVV=VV[s+1]-VV[s]
dV=0
for i in range(1,L-1):
for j in range(1,L-1):
dV=dV+abs(dVV[i][j])
print dV,L
s=s+1
if dV<error*(L-1)**2 and s>1:
break
return s
L=[]
NJ=[]
NGS=[]
NSOR=[]
f=open('problem5.7.txt','w')
print >> f,'L','J','GS','SOR'
for i in range(6,61,5):
J=Jacobi(i)
G=GS(i)
S=SOR(i)
L.append(i)
NJ.append(J)
NGS.append(G)
NSOR.append(S)
print >> f,i,J,G,S
f.close()
plot(L,NJ)
plot(L,NGS)
plot(L,NSOR)
scatter(L,NJ)
scatter(L,NGS)
scatter(L,NSOR)
legend(('Jacobi method','GS method','SOR method'),'upper left')
title('3 different methods',fontsize=15)
xlabel('L')
ylim(0,1000)
ylabel('N')
savefig('different methods.png')
show()
problem5.4
First of all, we investigate that the plate separation as 0.8(m)
Then we change the plate separation to 1(m)
Last we change the plate separation to 1.2(m)
problem5.7
Comparing 3 different methods, the figure shows that convergent speeds SOR method > GS method > Jacobi method.