主题:程序运行无正确结果,如何改正?
这个超松弛迭代程序为何一直不收敛,谁能帮助改正?
subroutine ssor(a,b,c,d,e,f,g,n,m,x,eps,om,ii)
parameter(imax=100000)
real a(n,m),b(n,m),c(n,m),d(n,m),e(n,m),f(n,m),g(n+1,m+1),x(n+1,m+1)
integer i,j,ii
do ii=1,imax
s=0.0
t=0.0
do i=2,n
do j=2,m
g(i,j)=x(i,j)
x(i,j)=om*((a(i,j)*x(i+1,j)+b(i,j)*x(i-1,j)+c(i,j)*x(i,j+1)+d(i,j)*x(i,j-1)-f(i,j))/e(i,j)-g(i,j))+g(i,j)
s=s+abs(x(i,j)-g(i,j))
t=t+abs(x(i,j))
enddo
enddo
if(s/t<=eps)return
enddo
pause 'too many iterations'
end subroutine ssor
program dir12
! drive program for routine ssor
parameter(n=200,m=100,eps=1.e-3,om=1.6)
parameter(u=0.03141593,w=0.1744444,z=0.02,p=2.467403)
dimension a(n,m),a1(n,m),b(n,m),b1(n,m),c(n,m),c1(n,m)&
,d(n,m),d1(n,m),e(n,m),e1(n,m),f(n,m),f1(n,m),x(n+1,m+1)
do i=1,n+1
x(i,1)=0.0
x(i,101)=0.0
enddo
do j=1,m+1
x(1,j)=0.0
x(201,j)=0.0
enddo
do i=2,n
do j=2,m
a1(i,j)=(1+(z*(j-1)*w)*cos((i-0.5)*u))**3
b1(i,j)=(1+(z*(j-1)*w)*cos((i-1.5)*u))**3
c1(i,j)=p*(1+(z*(j-0.5)*w)*cos((i-1)*u))**3
d1(i,j)=p*(1+(z*(j-1.5)*w)*cos((i-1)*u))**3
e1(i,j)=a1(i,j)+b1(i,j)+c1(i,j)+d1(i,j)
f1(i,j)=3*u*(z*(j-1)*w)*(cos((i-0.5)*u)-cos((i-1.5)*u))
enddo
enddo
do i=2,n
do j=2,m
a(i,j)=a1(i,j)
b(i,j)=b1(i,j)
c(i,j)=c1(i,j)
d(i,j)=d1(i,j)
e(i,j)=e1(i,j)
f(i,j)=f1(i,j)
enddo
enddo
do l=2,n
do k=2,m
x(l,k)=0.0
enddo
enddo
call ssor(a,b,c,d,e,f,g,n,m,x,eps,om,ii)
write(*,*) 'solution vector',x
write(*,*) 'iteration times=',ii
end
subroutine ssor(a,b,c,d,e,f,g,n,m,x,eps,om,ii)
parameter(imax=100000)
real a(n,m),b(n,m),c(n,m),d(n,m),e(n,m),f(n,m),g(n+1,m+1),x(n+1,m+1)
integer i,j,ii
do ii=1,imax
s=0.0
t=0.0
do i=2,n
do j=2,m
g(i,j)=x(i,j)
x(i,j)=om*((a(i,j)*x(i+1,j)+b(i,j)*x(i-1,j)+c(i,j)*x(i,j+1)+d(i,j)*x(i,j-1)-f(i,j))/e(i,j)-g(i,j))+g(i,j)
s=s+abs(x(i,j)-g(i,j))
t=t+abs(x(i,j))
enddo
enddo
if(s/t<=eps)return
enddo
pause 'too many iterations'
end subroutine ssor
program dir12
! drive program for routine ssor
parameter(n=200,m=100,eps=1.e-3,om=1.6)
parameter(u=0.03141593,w=0.1744444,z=0.02,p=2.467403)
dimension a(n,m),a1(n,m),b(n,m),b1(n,m),c(n,m),c1(n,m)&
,d(n,m),d1(n,m),e(n,m),e1(n,m),f(n,m),f1(n,m),x(n+1,m+1)
do i=1,n+1
x(i,1)=0.0
x(i,101)=0.0
enddo
do j=1,m+1
x(1,j)=0.0
x(201,j)=0.0
enddo
do i=2,n
do j=2,m
a1(i,j)=(1+(z*(j-1)*w)*cos((i-0.5)*u))**3
b1(i,j)=(1+(z*(j-1)*w)*cos((i-1.5)*u))**3
c1(i,j)=p*(1+(z*(j-0.5)*w)*cos((i-1)*u))**3
d1(i,j)=p*(1+(z*(j-1.5)*w)*cos((i-1)*u))**3
e1(i,j)=a1(i,j)+b1(i,j)+c1(i,j)+d1(i,j)
f1(i,j)=3*u*(z*(j-1)*w)*(cos((i-0.5)*u)-cos((i-1.5)*u))
enddo
enddo
do i=2,n
do j=2,m
a(i,j)=a1(i,j)
b(i,j)=b1(i,j)
c(i,j)=c1(i,j)
d(i,j)=d1(i,j)
e(i,j)=e1(i,j)
f(i,j)=f1(i,j)
enddo
enddo
do l=2,n
do k=2,m
x(l,k)=0.0
enddo
enddo
call ssor(a,b,c,d,e,f,g,n,m,x,eps,om,ii)
write(*,*) 'solution vector',x
write(*,*) 'iteration times=',ii
end