-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2-Reverse.pas
131 lines (114 loc) · 2.29 KB
/
2-Reverse.pas
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
PROGRAM gauss;
USES crt;
TYPE
Matr = ARRAY [1..20, 1..20] OF REAL;
Vect = ARRAY [1..20] OF REAL;
PROCEDURE MainEl(VAR a: Matr; VAR e: Matr; t, m: WORD);
VAR
i,j,k,s: WORD;
u,v: Vect;
p: REAL;
BEGIN
FOR j := t TO m DO
BEGIN
p := a[j,j];
FOR i := j TO m DO
BEGIN
IF Abs(a[i,j]) >= Abs(p) THEN
BEGIN
p := a[i,j];
s := i;
END;
END;
FOR k := 1 TO m DO
BEGIN
u[k] := a[s,k];
a[s,k] := a[j,k];
a[j,k] := u[k];
v[k] := e[s,k];
e[s,k] := e[j,k];
e[j,k] := v[k];
END;
IF Abs(a[j,j]) = 0 THEN
BEGIN
WriteLn;
WriteLn('Matrix is degenerate!');
ReadKey;
Exit;
END;
END;
END;
{Solution}
VAR
a,x,e: Matr;
i,j,n,m,k: WORD;
t: REAL;
BEGIN
ClrScr;
Write('Input dimension = '); ReadLn(n);
IF n < 2 THEN
WriteLn('Need n >= 2!');
FOR i := 1 TO n DO
BEGIN
FOR j := 1 TO n DO
BEGIN
Write('a(', i, ', ', j, ') = '); ReadLn(a[i,j]);
IF i <> j THEN
e[i,j] := 0
ELSE e[i,j] := 1;
END;
END;
FOR i := 1 TO n DO
BEGIN
MainEl(a,e,i,n);
t := a[i,i];
FOR j := 1 TO n DO
BEGIN
a[i,j] := a[i,j] / t;
e[i,j] := e[i,j] / t;
END;
FOR k := (i+1) TO n DO
BEGIN
t := a[k,i];
FOR j := 1 TO n DO
BEGIN
e[k,j] := e[k,j] - e[i,j] * t;
END;
FOR j := i TO n DO
BEGIN
a[k,j] := a[k,j] - a[i,j] * t;
END;
END;
FOR k := (i-1) DOWNTO 1 DO
BEGIN
t := a[k,i];
FOR j := 1 TO n DO
BEGIN
e[k,j] := e[k,j] - e[i,j] * t;
END;
FOR j := i TO n DO
BEGIN
a[k,j] := a[k,j] - a[i,j] * t;
END;
END;
END;
WriteLn;
FOR i := 1 TO n DO
BEGIN
FOR j := 1 TO n DO
BEGIN
Write(' ', a[i,j]:3:1);
END;
WriteLn;
END;
WriteLn;
FOR i := 1 TO n DO
BEGIN
FOR j := 1 TO n DO
BEGIN
Write(' ', e[i,j]:3:1);
END;
WriteLn;
END;
ReadKey;
END.