Академический Документы
Профессиональный Документы
Культура Документы
. (1)
(2)
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
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