Вы находитесь на странице: 1из 7

NUMERICAL SOLUTION OF LAPLACE EQUATION

Laplace equation in two dimensions can be approximated by the finite differences


equation
{(x + x, y)- 2(x,y) + (x-x,y) }/x2 + {(x , y +y)- 2(x,y) + (x,y -y) }/y2 = 0

. (1)

The central point value satisfies


(x,y) = (1/4) {(x + x, y) + (x-x,y) +(x , y +y) + (x,y -y) } .

(2)

Suppose a potential in a square of dimension 1 by 1 is given along the boundaries by


the relations
(x, 1)= 0

, (1 ,y) = 400 y , (0, y) = 0 , (x, 1)= 400 x .

One can tell that the potential is (x, y) = 400 x y . Nevertheless for our example we
carry on obtaining a numerical solution by iterations. Equation (2) is used iteratively.
The n-th value depends on the previous (n-1)th value,
n (x,y) = (1/4) {n-1(x + x, y) + n-1(x-x,y) + n-1(x , y +y) + n-1(x,y -y) } . (3)

In the FORTAN code given we divide the grid in 100 points (nx= ny= 10) and carry
60 iterations.
We assign an initial value of 0 (x,y) = 200 , to all interior points.
The biggest errors are of the order 10 %.

Results
x

400*x*y

x,y,phi,u= 0.000E+00 0.000E+00 0.000E+00 0.000E+00


x,y,phi,u= 0.000E+00 0.100E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.200E+00 0.000E+00 0.000E+00

x,y,phi,u= 0.000E+00 0.300E+00 0.000E+00 0.000E+00


x,y,phi,u= 0.000E+00 0.400E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.500E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.600E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.700E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.800E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.900E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.000E+00 0.100E+01 0.000E+00 0.000E+00
x,y,phi,u= 0.100E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.100E+00 0.100E+00 0.476E+01 0.400E+01
x,y,phi,u= 0.100E+00 0.200E+00 0.945E+01 0.800E+01
x,y,phi,u= 0.100E+00 0.300E+00 0.140E+02 0.120E+02
x,y,phi,u= 0.100E+00 0.400E+00 0.183E+02 0.160E+02
x,y,phi,u= 0.100E+00 0.500E+00 0.224E+02 0.200E+02
x,y,phi,u= 0.100E+00 0.600E+00 0.263E+02 0.240E+02
x,y,phi,u= 0.100E+00 0.700E+00 0.300E+02 0.280E+02
x,y,phi,u= 0.100E+00 0.800E+00 0.334E+02 0.320E+02
x,y,phi,u= 0.100E+00 0.900E+00 0.368E+02 0.360E+02
x,y,phi,u= 0.100E+00 0.100E+01 0.400E+02 0.400E+02
x,y,phi,u= 0.200E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.200E+00 0.100E+00 0.945E+01 0.800E+01
x,y,phi,u= 0.200E+00 0.200E+00 0.188E+02 0.160E+02
x,y,phi,u= 0.200E+00 0.300E+00 0.278E+02 0.240E+02
x,y,phi,u= 0.200E+00 0.400E+00 0.364E+02 0.320E+02
x,y,phi,u= 0.200E+00 0.500E+00 0.446E+02 0.400E+02
x,y,phi,u= 0.200E+00 0.600E+00 0.524E+02 0.480E+02
x,y,phi,u= 0.200E+00 0.700E+00 0.597E+02 0.560E+02
x,y,phi,u= 0.200E+00 0.800E+00 0.667E+02 0.640E+02
x,y,phi,u= 0.200E+00 0.900E+00 0.734E+02 0.720E+02
x,y,phi,u= 0.200E+00 0.100E+01 0.800E+02 0.800E+02
x,y,phi,u= 0.300E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.300E+00 0.100E+00 0.140E+02 0.120E+02
x,y,phi,u= 0.300E+00 0.200E+00 0.278E+02 0.240E+02
x,y,phi,u= 0.300E+00 0.300E+00 0.412E+02 0.360E+02
x,y,phi,u= 0.300E+00 0.400E+00 0.541E+02 0.480E+02
x,y,phi,u= 0.300E+00 0.500E+00 0.664E+02 0.600E+02
x,y,phi,u= 0.300E+00 0.600E+00 0.781E+02 0.720E+02
x,y,phi,u= 0.300E+00 0.700E+00 0.891E+02 0.840E+02

x,y,phi,u= 0.300E+00 0.800E+00 0.997E+02 0.960E+02


x,y,phi,u= 0.300E+00 0.900E+00 0.110E+03 0.108E+03
x,y,phi,u= 0.300E+00 0.100E+01 0.120E+03 0.120E+03
x,y,phi,u= 0.400E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.400E+00 0.100E+00 0.183E+02 0.160E+02
x,y,phi,u= 0.400E+00 0.200E+00 0.364E+02 0.320E+02
x,y,phi,u= 0.400E+00 0.300E+00 0.541E+02 0.480E+02
x,y,phi,u= 0.400E+00 0.400E+00 0.711E+02 0.640E+02
x,y,phi,u= 0.400E+00 0.500E+00 0.875E+02 0.800E+02
x,y,phi,u= 0.400E+00 0.600E+00 0.103E+03 0.960E+02
x,y,phi,u= 0.400E+00 0.700E+00 0.118E+03 0.112E+03
x,y,phi,u= 0.400E+00 0.800E+00 0.132E+03 0.128E+03
x,y,phi,u= 0.400E+00 0.900E+00 0.146E+03 0.144E+03
x,y,phi,u= 0.400E+00 0.100E+01 0.160E+03 0.160E+03
x,y,phi,u= 0.500E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.500E+00 0.100E+00 0.224E+02 0.200E+02
x,y,phi,u= 0.500E+00 0.200E+00 0.446E+02 0.400E+02
x,y,phi,u= 0.500E+00 0.300E+00 0.664E+02 0.600E+02
x,y,phi,u= 0.500E+00 0.400E+00 0.875E+02 0.800E+02
x,y,phi,u= 0.500E+00 0.500E+00 0.108E+03 0.100E+03
x,y,phi,u= 0.500E+00 0.600E+00 0.127E+03 0.120E+03
x,y,phi,u= 0.500E+00 0.700E+00 0.146E+03 0.140E+03
x,y,phi,u= 0.500E+00 0.800E+00 0.165E+03 0.160E+03
x,y,phi,u= 0.500E+00 0.900E+00 0.182E+03 0.180E+03
x,y,phi,u= 0.500E+00 0.100E+01 0.200E+03 0.200E+03
x,y,phi,u= 0.600E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.600E+00 0.100E+00 0.263E+02 0.240E+02
x,y,phi,u= 0.600E+00 0.200E+00 0.524E+02 0.480E+02
x,y,phi,u= 0.600E+00 0.300E+00 0.781E+02 0.720E+02
x,y,phi,u= 0.600E+00 0.400E+00 0.103E+03 0.960E+02
x,y,phi,u= 0.600E+00 0.500E+00 0.127E+03 0.120E+03
x,y,phi,u= 0.600E+00 0.600E+00 0.151E+03 0.144E+03
x,y,phi,u= 0.600E+00 0.700E+00 0.174E+03 0.168E+03
x,y,phi,u= 0.600E+00 0.800E+00 0.196E+03 0.192E+03
x,y,phi,u= 0.600E+00 0.900E+00 0.218E+03 0.216E+03
x,y,phi,u= 0.600E+00 0.100E+01 0.240E+03 0.240E+03
x,y,phi,u= 0.700E+00 0.000E+00 0.000E+00 0.000E+00

x,y,phi,u= 0.700E+00 0.100E+00 0.300E+02 0.280E+02


x,y,phi,u= 0.700E+00 0.200E+00 0.597E+02 0.560E+02
x,y,phi,u= 0.700E+00 0.300E+00 0.891E+02 0.840E+02
x,y,phi,u= 0.700E+00 0.400E+00 0.118E+03 0.112E+03
x,y,phi,u= 0.700E+00 0.500E+00 0.146E+03 0.140E+03
x,y,phi,u= 0.700E+00 0.600E+00 0.174E+03 0.168E+03
x,y,phi,u= 0.700E+00 0.700E+00 0.201E+03 0.196E+03
x,y,phi,u= 0.700E+00 0.800E+00 0.228E+03 0.224E+03
x,y,phi,u= 0.700E+00 0.900E+00 0.254E+03 0.252E+03
x,y,phi,u= 0.700E+00 0.100E+01 0.280E+03 0.280E+03
x,y,phi,u= 0.800E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.800E+00 0.100E+00 0.334E+02 0.320E+02
x,y,phi,u= 0.800E+00 0.200E+00 0.667E+02 0.640E+02
x,y,phi,u= 0.800E+00 0.300E+00 0.997E+02 0.960E+02
x,y,phi,u= 0.800E+00 0.400E+00 0.132E+03 0.128E+03
x,y,phi,u= 0.800E+00 0.500E+00 0.165E+03 0.160E+03
x,y,phi,u= 0.800E+00 0.600E+00 0.196E+03 0.192E+03
x,y,phi,u= 0.800E+00 0.700E+00 0.228E+03 0.224E+03
x,y,phi,u= 0.800E+00 0.800E+00 0.259E+03 0.256E+03
x,y,phi,u= 0.800E+00 0.900E+00 0.289E+03 0.288E+03
x,y,phi,u= 0.800E+00 0.100E+01 0.320E+03 0.320E+03
x,y,phi,u= 0.900E+00 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.900E+00 0.100E+00 0.368E+02 0.360E+02
x,y,phi,u= 0.900E+00 0.200E+00 0.734E+02 0.720E+02
x,y,phi,u= 0.900E+00 0.300E+00 0.110E+03 0.108E+03
x,y,phi,u= 0.900E+00 0.400E+00 0.146E+03 0.144E+03
x,y,phi,u= 0.900E+00 0.500E+00 0.182E+03 0.180E+03
x,y,phi,u= 0.900E+00 0.600E+00 0.218E+03 0.216E+03
x,y,phi,u= 0.900E+00 0.700E+00 0.254E+03 0.252E+03
x,y,phi,u= 0.900E+00 0.800E+00 0.289E+03 0.288E+03
x,y,phi,u= 0.900E+00 0.900E+00 0.325E+03 0.324E+03
x,y,phi,u= 0.900E+00 0.100E+01 0.360E+03 0.360E+03
x,y,phi,u= 0.100E+01 0.000E+00 0.000E+00 0.000E+00
x,y,phi,u= 0.100E+01 0.100E+00 0.400E+02 0.400E+02
x,y,phi,u= 0.100E+01 0.200E+00 0.800E+02 0.800E+02
x,y,phi,u= 0.100E+01 0.300E+00 0.120E+03 0.120E+03
x,y,phi,u= 0.100E+01 0.400E+00 0.160E+03 0.160E+03
x,y,phi,u= 0.100E+01 0.500E+00 0.200E+03 0.200E+03

x,y,phi,u= 0.100E+01 0.600E+00 0.240E+03 0.240E+03


x,y,phi,u= 0.100E+01 0.700E+00 0.280E+03 0.280E+03
x,y,phi,u= 0.100E+01 0.800E+00 0.320E+03 0.320E+03
x,y,phi,u= 0.100E+01 0.900E+00 0.360E+03 0.360E+03
x,y,phi,u= 0.100E+01 0.100E+01 0.400E+03 0.400E+03

FORTRAN code
c LAPLACE IN Two DIM (X,Y) Burden & Faires page 571
implicit real*8 (a-h,o-z)
equivalence (x1,y1),(x2,y2),(dx,dy), (nx,ny)
dimension phi(0:100,0:100),phi1(0:100,0:100)
c F(x,y) is correct potentail
data x1,x2 /0.d0, 1.d0/
data niter/60/
f(x,y)= 400.d0*x*y
pi=2.d0*dasin(1.d0)
c limits of integration 0 <=x <=pi , same for y and z
nx=10
dx=(x2-x1)/dfloat(nx)
c Phi is set at the boundaries
do 205 n=0,nx
phi(0,n)=f(x1,dy*dfloat(n))
phi(n,0)=f(dx*dfloat(n),y1)
phi(nx,n)=f(x2,dy*dfloat(n))
phi(n,ny)=f(dx*dfloat(n),y2)

205 continue
c initial values assigned to the potential phi(i,j) loop do 30
c (at interior points)
do 30 iy=1,ny-1
y=dy*dfloat(iy)
do 30 ix=1,nx-1
x=dx*dfloat(ix)
phi(ix,iy)= 200.d0
30 continue
c integration iteration using finite differences
do 55 it=1,niter
do 35 iy= 1,ny-1
y=y1+dy*dfloat(iy)
do 35 ix=1,nx-1
x=x1+dx*dfloat(ix)
sumphi=(1.d0/4.d0)*( phi(ix+1,iy)+phi(ix-1,iy)+
$ phi(ix,iy+1)+phi(ix,iy-1))
phi1(ix,iy)= sumphi
35 continue
c relabel phi and phi1(excludes boundary values of Phi,which are fixed)
do 45 i=1,nx-1
do 45 j=1,ny-1
phi(i,j)=phi1(i,j)
45 continue
c 55 continue
c check phi vs potential u ~ (analytic)
if(it.eq.niter)then
do 65 i=0,nx
print*,' '
do 65 j=0,ny
x=x1+dx*dfloat(i)
y=y1+dy*dfloat(j)
print 130,x ,y, phi(i,j) ,f(x,y)
65 continue
endif
c print*,' '
55 continue
130 format(2x,'x,y,phi,u=',4(3x,d10.3))
stop
end

Вам также может понравиться