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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市蔑鹦,隨后出現(xiàn)的幾起案子叹俏,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呼盆,死亡現(xiàn)場(chǎng)離奇詭異寞钥,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)吭净,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門睡汹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人寂殉,你說(shuō)我怎么就攤上這事囚巴。” “怎么了不撑?”我有些...
    開封第一講書人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵文兢,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我焕檬,道長(zhǎng)姆坚,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任实愚,我火速辦了婚禮兼呵,結(jié)果婚禮上兔辅,老公的妹妹穿的比我還像新娘。我一直安慰自己击喂,他們只是感情好维苔,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著懂昂,像睡著了一般介时。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上凌彬,一...
    開封第一講書人閱讀 51,462評(píng)論 1 302
  • 那天沸柔,我揣著相機(jī)與錄音,去河邊找鬼铲敛。 笑死褐澎,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的伐蒋。 我是一名探鬼主播工三,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼先鱼!你這毒婦竟也來(lái)了俭正?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤焙畔,失蹤者是張志新(化名)和其女友劉穎段审,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體闹蒜,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡寺枉,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了绷落。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片姥闪。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖砌烁,靈堂內(nèi)的尸體忽然破棺而出筐喳,到底是詐尸還是另有隱情,我是刑警寧澤函喉,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布避归,位于F島的核電站,受9級(jí)特大地震影響管呵,放射性物質(zhì)發(fā)生泄漏梳毙。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一捐下、第九天 我趴在偏房一處隱蔽的房頂上張望账锹。 院中可真熱鬧萌业,春花似錦、人聲如沸奸柬。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)廓奕。三九已至抱婉,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間桌粉,已是汗流浹背授段。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留番甩,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓届搁,卻偏偏與公主長(zhǎng)得像缘薛,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子卡睦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 別自視清高宴胧。 天外有天,人上有人表锻,謙卑是一種態(tài)度恕齐,更是一種修養(yǎng)。擺正自己的位置瞬逊,權(quán)力是一時(shí)的显歧,金錢是身外的,身體是...
    耀磊閱讀 579評(píng)論 0 3
  • 不知道大家對(duì)于家是怎樣的概念,是港灣蕾域,是溫暖拷肌,是心安,還是無(wú)所畏懼旨巷,任意妄為巨缘,因?yàn)槲覀冎溃揖驮谀抢锊赡牛趺凑f(shuō)若锁,怎...
    叮兒想叮當(dāng)閱讀 2,680評(píng)論 0 1
  • 從昨天開始讀成甲老師的《好好學(xué)習(xí)——個(gè)人知識(shí)管理精進(jìn)指南》。這本書有很多大神推薦斧吐,所以我想應(yīng)該是一本不錯(cuò)的書拴清,我也...
    虎叔2018閱讀 2,537評(píng)論 0 3
  • 最近一個(gè)月太頹廢了靶病。 調(diào)整狀態(tài)ing
    貝爾微微閱讀 199評(píng)論 0 1