PROGRAM Laplace_equation_in_2D
parameter (kx=6,ky=6)
integer::i,j,n,k
real,dimension(6,6)::a,a1,err
open(1,file='laplace_input',status='unknown')
open(2,file='laplace_output',status='unknown')
read(1,*)((a(i,j),j=1,ky),i=1,kx)
k=0
n=0
3 do i=2,kx-1
do j=2,ky-1
a1(i,j)=0.25*(a(i+1,j)+a(i-1,j)+a(i,j+1)+a(i,j-1))
enddo
enddo
do i=2,kx-1
do j=2,ky-1
err(i,j)=a(i,j)-a1(i,j)
a(i,j)=a1(i,j)
if(abs(err(i,j))<=0.00001)n=n+1
if(n==(kx-1)*(ky-1))goto 11
enddo
enddo
k=k+1
goto 3
11 write(2,4)k
write(2,5)((a(i,j),j=1,6),i=1,6)
4 format('Number of Iteration=',i3)
5 format(6(f6.3,1x))
end
parameter (kx=6,ky=6)
integer::i,j,n,k
real,dimension(6,6)::a,a1,err
open(1,file='laplace_input',status='unknown')
open(2,file='laplace_output',status='unknown')
read(1,*)((a(i,j),j=1,ky),i=1,kx)
k=0
n=0
3 do i=2,kx-1
do j=2,ky-1
a1(i,j)=0.25*(a(i+1,j)+a(i-1,j)+a(i,j+1)+a(i,j-1))
enddo
enddo
do i=2,kx-1
do j=2,ky-1
err(i,j)=a(i,j)-a1(i,j)
a(i,j)=a1(i,j)
if(abs(err(i,j))<=0.00001)n=n+1
if(n==(kx-1)*(ky-1))goto 11
enddo
enddo
k=k+1
goto 3
11 write(2,4)k
write(2,5)((a(i,j),j=1,6),i=1,6)
4 format('Number of Iteration=',i3)
5 format(6(f6.3,1x))
end
Comments
Post a Comment