-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimlin_from_net.f
57 lines (57 loc) · 1.3 KB
/
simlin_from_net.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
C FIND SOLUTION USING GAUSS ELIMINATION BY PIVOTING METHOD
DIMENSION A(10,11), X(10)
WRITE (*,*) 'ENTER THE DIMENSION OF THE SYSTEM'
READ (*,*) N
WRITE (*,*) 'ENTER THE ELEMENTS OF BOTH A AND PRODUCT MATRIX'
WRITE (*,*) '(ROW-WISE)'
READ (*,*) ((A(I,J), J=1,N+1), I=1,N)
DO 10 K=1,N-1
CALL INTERCHANGE(N,A,K)
PIVOT = A(K,K)
DO 20 I=K+1,N
FACTOR = A(I,K)/PIVOT
DO 30 J=1,N+1
A(I,J) = A(I,J) - FACTOR*A(K,J)
30 CONTINUE
20 CONTINUE
10 CONTINUE
C ********** BACK SUBSTITUTION **********
X(N) = A(N,N+1)/A(N,N)
DO 40 K=N-1,1,-1
SUMM=0
DO 50 J=K+1,N
SUMM = SUMM + A(K,J)*X(J)
50 CONTINUE
X(K) = (A(K,N+1)-SUMM)/A(K,K)
40 CONTINUE
C ********** RESULT **********
WRITE (*,*) 'THE SOLUTION VECTOR IS:'
DO I=1,N
WRITE (*,60) I,X(I)
END DO
60 FORMAT ("X(",I2,")",F7.2)
STOP
END
C SUBROUTINE TO FIND THE LARGEST NO. & INTERCHANGE THE ROWS
C ***** TO FIND THE LARGEST ELEMENT IN THE COLUMN *****
SUBROUTINE INTERCHANGE (N,A,K)
DIMENSION A(10,11)
INTEGER ROW
ROW = K
LARGE = ABS (A(K,K))
DO 5 I=K+1,N
IF (ABS(A(I,K)) .GT. ABS(A(K,K))) THEN
LARGE = ABS(A(I,K))
ROW = I
END IF
5 CONTINUE
C ***** INTERCHANGING THE ITH ROW WITH KTH ROW *****
IF (ROW .NE. K) THEN
DO 6 J=1,N+1
TEMP = A(ROW,J)
A(ROW,J) = A(K,J)
A(K,J) = TEMP
6 CONTINUE
END IF
RETURN
END