# PROGRAM GAUSSSEIDEL IMPLICIT NONE !objetivo: resolver o sistema Ax=b pelo m‚todo iterativo de Gauss!

Seidel INTEGER:: I,J,K,ITERMAX,N,ITER,IO REAL *8:: TOLER,R,SOMA,T,NORMA_NUM, NORMA_DEN,NORMA_REL REAL *8, DIMENSION (:), ALLOCATABLE::B,X,V REAL *8, DIMENSION (:,:), ALLOCATABLE::A CHARACTER*16 FILEOUT IO=4 WRITE(*,' (A) ') ' NOME ARQ. SAIDA DE RESULTADOS ? (MAX 16 CHAR) ' READ(*,' (A) ')FILEOUT OPEN(IO,FILE=FILEOUT,STATUS='UNKNOWN')

1

WRITE(*,1) WRITE(IO,1) FORMAT(/,T2,'SISTEMA RESOLVIDO PELO METODO DE GAUSS-SEIDEL ',//) WRITE(*,12) WRITE(IO,12) FORMAT(T2,'ORDEM DA MATRIZ (N):',/) READ(*,*) N WRITE(IO,*) N ALLOCATE (B(N),X(N),V(N)) ALLOCATE (A(N,N)) WRITE(*,13) WRITE(IO,13) FORMAT(/,T2,'MATRIZ (A):') READ(*,*)((A(I,J),J=1,N),I=1,N) WRITE(IO,*)((A(I,J),J=1,N),I=1,N) WRITE(*,17) WRITE(IO,17) FORMAT(/,T2,'VETOR INDEPENDENTE (B):',/) READ(*,*) (B(I),I=1,N) WRITE(IO,*) (B(I),I=1,N) WRITE(*,14) WRITE(IO,14) FORMAT(/,T2,'TOLERANCIA (TOLER):',/) READ(*,*) TOLER WRITE(IO,*) TOLER WRITE(*,16) FORMAT(/,T2,'NUMERO MAXIMO DE ITERACOES (ITERMAX):',/) READ(*,*)ITERMAX

12

13

17

14

16

DO I=1,N R=1/A(I,I) DO J=1,N IF (I.NE.J) THEN A(I,J)=A(I,J)*R END IF END DO B(I)=B(I)*R X(I)=B(I) END DO ITER=0

!ITERAÇÕES DE GAUSS-SEIDEL DO WHILE(ITER.LE.ITERMAX) ITER=ITER+1 DO I=1,N SOMA=0 DO J=1,N IF (I.NE.J) THEN SOMA=SOMA+A(I,J)*X(J) END IF

1

NORMA_REL FORMAT(//.T1.N WRITE(IO.'NORMA_REL'.END DO V(I)=X(I) X(I)=B(I)-SOMA END DO NORMA_NUM=0 NORMA_DEN=0 DO I=1.T1.F12.T14.32)K.F12.I6.'ITER'.N T=ABS(X(I)-V(I)) IF (T.GE.31)ITER.ITER.LE./) DO K=1.I6.NORMA_DEN) THEN NORMA_DEN=ABS(X(I)) END IF END DO NORMA_REL=NORMA_NUM/NORMA_DEN WRITE(IO.GT.ITERMAX) THEN STOP END IF END DO END PROGRAM GAUSSSEIDEL 31 32 2 .'X'.GT.X(K) FORMAT(/.T14.OR.6.'='.TOLER .7) END DO !TESTE DE CONVERGENCIA IF (NORMA_REL.NORMA_NUM) THEN NORMA_NUM=T END IF IF (ABS(X(I)).