Escolar Documentos
Profissional Documentos
Cultura Documentos
f90 ---------------------------
!Gauss Seidel Method with relaxation
subroutine seidel(crit,n,mat,b,omega,x,residu,iter,rc)
parameter(ITERMAX=500) ! Maximal number of iterations
parameter(ONE=1.d0,TWO=2.d0,ZERO=0.d0)
integer crit, n, iter, rc
REAL*8 mat(n,n),b(n),omega
REAL*8 x(n),residu(n)
!*====================================================================*
!* *
!* seidel solves the linear system mat * x = b iteratively. *
!* Here mat is a nonsingular n x n matrix, b is the right hand *
!* side for the linear system and x is the solution. *
!* *
!* seidel uses the Gauss Seidel Method with relaxation for a given *
!* relaxation coefficient 0 < omega < 2. *
!* If omega = 1, the standard Gauss Seidel method (without *
!* relaxation) is performed. *
!* *
!*====================================================================*
!* *
!* Applications: *
!* ============= *
!* Solve linear systems with nonsingular system matrices that *
!* satisfy one of the following criteria: row sum criterion, *
!* column sum criterion or the criterion of Schmidt and v. Mises.*
!* Only if at least one of these criteria is satisfied for mat, *
!* convergence of the scheme is guaranteed [See BIBLI 11]. *
!* *
!*====================================================================*
!* *
!* Input parameters: *
!* ================ *
!* crit integer crit *
!* select criterion *
!* =1 : row sum criterion *
!* =2 : column sum criterion *
!* =3 : criterion of Schmidt-v.Mises *
!* other : no check *
!* n integer n ( n > 0 ) *
!* size of mat, b and x *
!* mat REAL*8 mat(n,n) *
!* Matrix of the liear system *
!* b REAL*8 b(n) *
!* Right hand side *
!* omega REAL*8 omega; (0 < omega < 2) *
!* Relaxation coefficient. *
!* x REAL*8 x(n) *
!* Starting vector for iteration *
!* *
!* Output parameters: *
!* ================== *
!* x REAL*8 x(n) *
!* solution vector *
!* residu REAL*8 residu(n) *
!* residual vector b - mat * x; close to zero vector *
!* iter integer iter *
!* Number of iterations performed *
!* rc integer return code *
!* = 0 solution has been found *
!* = 1 n < 1 or omega <= 0 or omega >= 2 *
!* = 2 improper mat or b or x (not used here) *
!* = 3 one diagonal element of mat vanishes *
!* = 4 Iteration number exceeded *
!* = 11 column sum criterion violated *
!* = 12 row sum criterion violated *
!* = 13 Schmidt-v.Mises criterion violated *
!* *
!*====================================================================*
REAL*8 tmp, eps;
if (n<1.or.omega<=ZERO.or.omega>=TWO) then
rc=1
return
end if
eps = 1.d-10
end do
do i=1, n
residu(i) = x(i) !store x in residu
end do
iter=iter+1
do i=1, n
tmp=b(i)
do j=1, n
tmp = tmp - mat(i,j) * residu(j)
end do
residu(i) = residu(i) + omega * tmp
end do
return
end
! ----------------------- END fseidel.f90 ----------------------------