C FIGURE 0.4.6 SUBROUTINE TRI(A,B,C,X,F,N) IMPLICIT DOUBLE PRECISION(A-H,O-Z) C C ARGUMENT DESCRIPTIONS C C A,B,C - (INPUT) A,B,C ARE VECTORS OF LENGTHS N HOLDING THE C SUBDIAGONAL, DIAGONAL AND SUPERDIAGONAL OF THE TRIDIAGONAL C MATRIX IN THE LINEAR SYSTEM. C (OUTPUT) A,B,C ARE DESTROYED. C X - (OUTPUT) X IS THE SOLUTION VECTOR OF LENGTH N. C F - (INPUT) F IS THE RIGHT HAND SIDE VECTOR OF LENGTH N. C N - (INPUT) N IS THE NUMBER OF EQUATIONS AND NUMBER OF UNKNOWNS. C DIMENSION A(N),B(N),C(N),D(N),X(N),F(N),F_(N) C COPY F TO F_, SO F WILL NOT BE DESTROYED DO 5 I=1,N F_(I) = F(I) D(I) = 0.0 5 CONTINUE C BEGIN FORWARD ELIMINATION DO 10 K=1,N-1 IF (ABS(A(K+1)).GT.ABS(B(K))) THEN C SWITCH ROWS K AND K+1 TEMP = B(K) B(K) = A(K+1) A(K+1) = TEMP TEMP = C(K) C(K) = B(K+1) B(K+1) = TEMP TEMP = F_(K) F_(K) = F_(K+1) F_(K+1) = TEMP IF (K.LT.N-1) THEN TEMP = D(K) D(K) = C(K+1) C(K+1) = TEMP ENDIF ENDIF IF (B(K).EQ.0.D0) GO TO 20 AMUL = -A(K+1)/B(K) B(K+1) = B(K+1)+AMUL*C(K) F_(K+1) = F_(K+1)+AMUL*F_(K) IF (K.LT.N-1) THEN C(K+1) = C(K+1)+AMUL*D(K) ENDIF 10 CONTINUE C BACK SUBSTITUTION IF (B(N).EQ.0.0) GO TO 20 X(N) = F_(N)/B(N) X(N-1) = (F_(N-1)-C(N-1)*X(N))/B(N-1) DO 15 K=N-2,1,-1 X(K) = (F_(K)-C(K)*X(K+1)-D(K)*X(K+2))/B(K) 15 CONTINUE RETURN C THE MATRIX IS SINGULAR 20 PRINT 25 25 FORMAT (' THE MATRIX IS SINGULAR') RETURN END