Python program to find the potential distribution inside a resistor, by solving laplace equation.

© All Rights Reserved

55 views

Python program to find the potential distribution inside a resistor, by solving laplace equation.

© All Rights Reserved

- JEE Main 2019 Mathematics April Attempt Shift - 1(09th April, 2019)
- thesis
- Physical Significance of Bernoulli & Euler's Eqns
- Jharkhand Board, Class 12 Model Question Paper - Mathematics 2013
- Std10-Maths-TM-1.pdf
- Shifting Properties Example Sheets
- Eliptic Grid Generation
- Conformal_Flow.pdf
- SMN 14.4 Tangent Plane
- Elmwood C MS
- LineClipping 11 Sep
- Jackson 2 12 Homework Solution
- Excel functions reference
- JJCP1Sol
- poisson
- m2 u2 theory sheet1 lt
- Test3
- Elementary statistic
- Class XII Mathematics)
- [Greenberg M.] Advanced Engineering Mathematic. So(Z-lib.org)

You are on page 1of 4

Shyam Shankar H R

EE15B127

Electrical Dept.

February 23, 2017

1 Introduction

This report contains the solutions of the week-5 assignment of EE2307. The answers to the questions, the python code, and

the plots obtained are entered below.

from pylab import *

from numpy import *

import mpl_toolkits.mplot3d.axes3d as p3

print Enter arguments in the form Nx Ny Nbegin Nend Niter

if(len(sys.argv)==6):

Nx=int(sys.argv[1])

Ny=int(sys.argv[2])

else:

Nx=30

Ny=30

def potential(Nx,Ny):

Nbegin = 0

Nend = Ny

Niter = 2000 #.... Initialising the phi matrix (with electrode potential)

phi = zeros((Nx,Ny))

phi[0,Nbegin:Nend] = 1

phi[Ny-1,Nbegin:Nend] = 0

errors = zeros(Niter)

print phi

for k in arange(Niter):

#.... saving a copy for error check.....

oldphi = phi.copy()

#.... updating phi array.........

phi[1:-1,1:-1] = 0.25*(phi[1:-1,0:-2]+phi[1:-1,2:]+phi[0:-2,1:-1]+phi[2:,1:-1])

#.... assering boundaries.......

phi[1:-1,0] = phi[1:-1,1]

phi[1:-1,Nx-1] = phi[1:-1,Nx-2

phi[0,0:Nbegin] = phi[1,0:Nbegin

phi[0,Nend:] = phi[1,Nend:]

phi[Ny-1,0:Nbegin] = phi[Ny-2,0:Nbegin]

phi[Ny-1,Nend:] = phi[Ny-2,Nend:]

#.... computing error........

errors[k] = (abs(oldphi-phi)).max()

k = arange(Niter)

1

#....... Getting best-fit line

#..... y = mx+c ==> x(m)+ 1(c) = y

#M c = b form, where M = [x 1], b = y

# So, c = lstsq(M,b)

b = arange(Niter)

M1 = zeros((Niter,2))

M1[:,0] = 1 M1[:,1] = b

b = log(errors)

c = lstsq(M1,b)[0]

M2 = zeros((Niter-500,2))

b2=arange(500,Niter)

M2[:,0]=1

M2[:,1]=b2

b2=log(errors[500:])

c2=lstsq(M2,b2)[0]

x=linspace(0,Niter-1,Niter)

#.... Error v/s iterations plot .....

fig1 = figure()

semilogy(k,errors,ro,markevery=50)

semilogy(x, exp(c[0]+c[1]*x), r)

semilogy(x[500:],exp((c2[0]+c2[1]*x[500:])),g)

suptitle("Evolution of error with iteration", fontsize=20)

xlabel("iteration", fontsize=16)

ylabel("error (log scale)", fontsize=16)

savefig("fig_err.pdf")

#.... Surface plot of potential ......

fig2 = figure(4)

ax = p3.Axes3D(fig2) #... Axes3D is used to do the surface plot

x = arange(1,Nx+1)

y = arange(1,Ny+1)

X,Y = meshgrid(x,y) #... creates arrays out of x and y

title("3-D surface plot of the potential")

surf = ax.plot_surface(Y, X, phi, rstride=1, cstride=1, cmap=cm.jet, linewidth=0)

savefig("fig_surf.pdf")

#.... Contour plot of potential ......

fig3 = figure()

title("Contour plot of potential (Equipotential lines)")

cp = contour(Y, X, phi)

clabel(cp, inline=True, fontsize=10)

savefig("fig_cont.pdf")

#..... Evaluating current .....

fig4 = figure() Jx = zeros((Nx,Ny))

Jy = zeros((Nx,Ny))

Jx[1:-1,1:-1] = 0.5*(phi[1:-1,0:-2]-phi[1:-1,2:])

Jy[1:-1,1:-1] = 0.5*(phi[0:-2,1:-1]-phi[2:,1:-1])

quiver(y,x,Jy.transpose(),Jx.transpose())

title("Vector plot of the current flow")

savefig("fig_cur.pdf")

show()

return phi

phi = potential(Nx,Ny)

E=zeros(Nx)

for i in range(Ny):

E[i]=sum(pow((phi[:,i]-1*(Ny-i)/Ny),2))

E1=sum(E)/(Nx*Ny)

print E1

2

1.2 Theory

The potential distribution inside resistor is found by solving Laplace equation:

2 = 0

i+1,j + i1,j + i,j+1 + i,j1

i,j =

4

Here we utilize vectors for time-efficiency.Thus the potential at any point should be the average of its neighbours.

We keep iterating till the solution converges, i.e, max change of elements in fall below a certain value (tolerance). At

boundaries where the electrode is present, we just put the value of potential itself. At boundaries where there is no electrode,

the current should be tangential because charge cant leap out of the material into air. Since current is proportional to the

Electric Field, what this means is the gradient of should be tangential. This is implemented by requiring that should not

vary in the normal direction.

(For all cases, electrode potentials are taken +1V (top) and 0V (bottom))

1. For Nx = 30, Ny =30, Nxbegin = 10, Nend = 20

10 0

error

fit1 1.0

10 -1 fit2

0.8

error (log scale)

0.6

10 -2

0.4

10 -3 0.2

0.0

30

10 -4 25

20

0 15

5

10 -5 10 10

0 500 1000 1500 2000 15

20 5

iteration 25

30 0

30 Contour plot of potential (Equipotential lines) 30 Vector plot of the current flow

25 25

20 20

0.600

0.300

15 15

0.450

0.900

0.750

0.150

10 10

5

5

0

5 10 15 20 25 30 0 5 10 15 20 25 30

3

2. For Nx = 30, Ny =30, Nxbegin = 0, Nend = 30 (electrode covering surfaces)

10 0

error

fit1 1.0

10 -1 fit2

0.8

10 -2

error (log scale)

0.6

10 -3 0.4

0.2

10 -4

0.0

30

10 -5 25

20

0 15

5

10 -6 0 10 10

500 1000 1500 2000 15

20 5

iteration 25

30 0

30 Contour plot of potential (Equipotential lines) 30 Vector plot of the current flow

25 25

20 20

15 15

0.900

0.750

0.600

0.450

0.300

0.150

10 10

5

5

0

5 10 15 20 25 30 0 5 10 15 20 25 30

Calling the function for the case of the electrode covering the entire top and bottom surfaces, we obtain a potential distribution:

i,j . To compute the least square deviation, we use:

1 X L yi 2

2 = (i,j V0 )

Nx Ny i,j L

For Nx = 30, Ny = 30, with electrodes covering the entire top and bottom surfaces, we get 2 = 0.338

Similarly, for Nx = 60, Ny = 60, 2 = 0.254, and for Nx = 150, Ny = 150, 2 = 0.106.

We observe that2 decreases as the electrode size increases. It is because as the electrode size increases, the fringing effect

involed in the field distribution becomes insignificant. This enables the computed values to resemble the physical values to a

greater extent. The value of 2 doesnt approach zero in reasonable time, since the algorithm used is not so good.

- JEE Main 2019 Mathematics April Attempt Shift - 1(09th April, 2019)Uploaded byResonance Eduventures
- thesisUploaded bySri Sai
- Physical Significance of Bernoulli & Euler's EqnsUploaded byD.Viswanath
- Jharkhand Board, Class 12 Model Question Paper - Mathematics 2013Uploaded byAkshay Pandey
- Std10-Maths-TM-1.pdfUploaded byTNPSCbooksmaterials
- Shifting Properties Example SheetsUploaded bymeenafrazier
- Eliptic Grid GenerationUploaded bypadmanathan
- Conformal_Flow.pdfUploaded byPeter John Bolgert
- SMN 14.4 Tangent PlaneUploaded byMUSMADIYANA BINTI MD DAYAN
- LineClipping 11 SepUploaded byYash Gupta
- Jackson 2 12 Homework SolutionUploaded byJohn Holman
- poissonUploaded byDavid Dalzell
- Elmwood C MSUploaded byKonstantinos Konstantinou
- Excel functions referenceUploaded byOwain Evans
- m2 u2 theory sheet1 ltUploaded byapi-286106888
- Test3Uploaded byRajat Kalia
- JJCP1SolUploaded bySheila Chai
- Elementary statisticUploaded byAzilah Usman
- Class XII Mathematics)Uploaded bySonal Pawa
- [Greenberg M.] Advanced Engineering Mathematic. So(Z-lib.org)Uploaded byShri Nath Garg
- Lesson Template MathemaicsUploaded byMurali Sambhu
- 20094em3 Exercise 11Uploaded byapi-25895802
- Limit ProofsUploaded byRafael Cantagalli
- Extra Practice Set 1.docxUploaded byTeacher Mazita Idrissi School
- MATH 5-1Uploaded byJocy Carillo Lpt
- 1_4Uploaded bydelhiprashant
- sally sets up her jewellery store each sunday morning at the meet street marketsUploaded byapi-265609825
- Penggunaan Transformasi Lapplace2Uploaded bysantaimen
- vision setting guidance - 2014-2015Uploaded byapi-232035921
- wholegraphingpacketUploaded byapi-227793309

- Deep LearningUploaded byShyam Shankar
- Client Server programming C codeUploaded byShyam Shankar
- QueuingTheory Matlab AssignmentUploaded byShyam Shankar
- AssignmentUploaded byShyam Shankar
- Control engineeringUploaded byShyam Shankar
- Creative Engineering projectUploaded byShyam Shankar
- Analog System LabUploaded byShyam Shankar
- python2.pdfUploaded byShyam Shankar
- ReportUploaded byShyam Shankar
- Damping modelUploaded byShyam Shankar
- PMMC experimentUploaded byShyam Shankar
- Principles of measurementUploaded byShyam Shankar
- Communication Systems tutorialUploaded byShyam Shankar
- ReportUploaded byShyam Shankar
- PUSH with PC relative addressingUploaded byShyam Shankar
- Full BridgeUploaded byShyam Shankar
- Implementation of a Real-Time Spectrum Analyzer.pdfUploaded bytesfayebb
- solns_ch3.pdfUploaded bySoumitra Bhowmick
- Communication systemsUploaded byShyam Shankar
- 8085 problem setUploaded byShyam Shankar
- answer.pdfUploaded byShyam Shankar
- Report.pdfUploaded byShyam Shankar
- IEEE-754 floating point multipler in VerilogUploaded byShyam Shankar
- SyllabusUploaded byShyam Shankar
- 5c.txtUploaded byShyam Shankar
- python1.pdfUploaded byAnirudth N

- 9 OWG500210 Dual-homing Principle and Configuration(VMSC) ISSUE1.0Uploaded byHoàng Quốc Vương
- acme university shared services provider type iiUploaded byapi-374798111
- MITSUBISHI_GOT2000-Users-Manual-Utility.pdfUploaded bytien khongduochoi
- T4 Functional CV1Uploaded byJovan Stoimenovski
- EDiTH Getting_Started 07-2011Uploaded bymole_68
- HP MSR2000 Router Series J 2Uploaded byMarvin Edu Toledo Castro
- P4M8OOPRO-M_V2.0Uploaded bymvnet123
- uzicko-kolo-download-free.pdfUploaded bySkeledzic Stefan
- Ict SamplePaper Paper1 2D eUploaded bychanchihung
- Iec 61850 ImpUploaded byMuhammad Danish Shaikh
- A completely real time approach to process control education.pdfUploaded bykaye
- BalaGurusamyUploaded byAshok Yadav
- Css TutorialUploaded byrahul
- TestUploaded byraamji
- Tibco OverviewUploaded byJackson Wanjohi
- Forum.xda Developers58799Uploaded byturuc
- aten kvmUploaded byRudini Rayyan
- Is It Possible To Add New Lines To A Standard Purchase Order Via PdoiUploaded byqeasd123
- 0000bhartendu SinhaUploaded byRavikumar Subbiah
- digital design introUploaded byabhipankaj
- Evermotion Archmodel Vol 105 PDFUploaded byHector
- Jumping ball android gameUploaded byMukesh Kumar Jasrotia
- An Example of the Effectiveness of Directional Overcurrent Relays (ANSI 67, 67N) _ EEPUploaded bycatalincc
- Data WarehouseUploaded byShamim Ahmed
- Getting Started With Unlimited MayaUploaded byRahul
- Step-by-Step-Dus-Integration.docxUploaded byEmerson Eduardo Rodrigues
- The Journey to Digital MaturityUploaded byCecabank
- FibonacciUploaded byDaniel Nesprias
- Project Proposal - BlogUploaded byThenage Anton Chaminda Fernando
- Approximation of Integrals Over Rectangular RegionsUploaded byrodwellhead