C FIGURE 0.1.2 SUBROUTINE LINEQ(A,X,B,N) IMPLICIT DOUBLE PRECISION(A-H,O-Z) C C ARGUMENT DESCRIPTIONS C C A - (INPUT) A IS THE N BY N MATRIX IN THE LINEAR SYSTEM A*X=B. C (OUTPUT) A IS DESTROYED. C X - (OUTPUT) X IS THE SOLUTION VECTOR OF LENGTH N. C B - (INPUT) B IS THE RIGHT HAND SIDE VECTOR OF LENGTH N. C N - (INPUT) N IS THE NUMBER OF EQUATIONS AND NUMBER OF UNKNOWNS C IN THE LINEAR SYSTEM. C DIMENSION A(N,N),X(N),B(N),B_(N) C COPY B TO B_, SO B WILL NOT BE DESTROYED DO 5 I=1,N B_(I) = B(I) 5 CONTINUE C BEGIN FORWARD ELIMINATION DO 50 K=1,N-1 IBIG = K BIG = ABS(A(K,K)) C FIND THE LARGEST POTENTIAL PIVOT DO 10 I=K+1,N IF (ABS(A(I,K)).GT.BIG) THEN BIG = ABS(A(I,K)) IBIG = I ENDIF 10 CONTINUE IF (BIG.EQ.0.D0) GO TO 80 C SWITCH ROW K WITH THE ROW (IBIG) C CONTAINING THE LARGEST POTENTIAL PIVOT DO 20 J=K,N TEMP = A(IBIG,J) A(IBIG,J) = A(K,J) A(K,J) = TEMP 20 CONTINUE TEMP = B_(IBIG) B_(IBIG) = B_(K) B_(K) = TEMP DO 40 I=K+1,N AMUL = -A(I,K)/A(K,K) IF (AMUL.EQ.0.D0) GO TO 40 C ADD AMUL TIMES ROW K TO ROW I DO 30 J=K,N A(I,J) = A(I,J)+AMUL*A(K,J) 30 CONTINUE B_(I) = B_(I)+AMUL*B_(K) 40 CONTINUE 50 CONTINUE IF (A(N,N).EQ.0.0) GO TO 80 C BEGIN BACK SUBSTITUTION X(N) = B_(N)/A(N,N) DO 70 K=N-1,1,-1 SUM = 0 DO 60 J=K+1,N SUM = SUM + A(K,J)*X(J) 60 CONTINUE X(K) = (B_(K)-SUM)/A(K,K) 70 CONTINUE RETURN C IF THE LARGEST POTENTIAL PIVOT IS ZERO, C THE MATRIX IS SINGULAR. 80 PRINT 90 90 FORMAT (' THE MATRIX IS SINGULAR') RETURN END