Exercise 12:Electric Potential and Fields

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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,884评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,347评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,435评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,509评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,611评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,837评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,987评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,730评论 0 267
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,194评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,525评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,664评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,334评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,944评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,764评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,997评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,389评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,554评论 2 349

推荐阅读更多精彩内容

  • 别自视清高。 天外有天,人上有人,谦卑是一种态度,更是一种修养。摆正自己的位置,权力是一时的,金钱是身外的,身体是...
    耀磊阅读 575评论 0 3
  • 不知道大家对于家是怎样的概念,是港湾,是温暖,是心安,还是无所畏惧,任意妄为,因为我们知道,家就在那里,怎么说,怎...
    叮儿想叮当阅读 2,675评论 0 1
  • 从昨天开始读成甲老师的《好好学习——个人知识管理精进指南》。这本书有很多大神推荐,所以我想应该是一本不错的书,我也...
    虎叔2018阅读 2,530评论 0 3
  • 最近一个月太颓废了。 调整状态ing
    贝尔微微阅读 198评论 0 1