-
Notifications
You must be signed in to change notification settings - Fork 3
/
lower.py
72 lines (61 loc) · 2.49 KB
/
lower.py
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
import Matrix
from Identity import Identity
from Rational import Rational as R
Lower = Matrix.Matrix([[R(1), R(0), R(0), R(0)],
[R(-1, 2), R(1), R(0), R(0)],
[R(-2), R(0), R(1), R(0)],
[R(-1), R(4, 5), R(2, 9), R(1)]])
def lower(matrix):
#pas fini
nb_line = len(matrix.matrix)
En = Identity(nb_line)
for k in range (nb_line - 1): #E_{n-1} ... E_{1}
#Create empty matrix
E = []
for i in range(nb_line):
E.append([])
#Create E_{n}^{-1} matrix
for column in range (nb_line):
for line in range (nb_line):
if column == line: #in the diagonal
E[line].append(R(1))
elif k == column and column < line:
E[line].append( matrix[line][k] / matrix[k][k])
else:
E[line].append(R(0))
E = Matrix.Matrix(E)
En = En * E
#---------------------
#multiply matrix by E
#---------------------
E = E.matrix
#Create E_{n}^{-1} matrix
for column in range (nb_line):
for line in range (nb_line):
if column == line: #in the diagonal
pass
else:
E[column][line] = R(0)-E[column][line]
#AFAIRE ! matrix deviens matrix * E_{n}
E = Matrix.Matrix(E)
matrix = E * matrix
#-------------------------
return En
if __name__ == "__main__":
A = Matrix.Matrix([[R(2), R(3), R(3), R(1)],
[R(-1), R(1), R(1), R(1)],
[R(-4), R(-6), R(3), R(2)],
[R(-2), R(-1), R(1), R(1)]])
Lower = Matrix.Matrix([[R(1), R(0), R(0), R(0)],
[R(-1, 2), R(1), R(0), R(0)],
[R(-2), R(0), R(1), R(0)],
[R(-1), R(4, 5), R(2, 9), R(1)]])
An = lower(A)
print (An)
#print(Lower)
Upper = Matrix.Matrix([ [R(2), R(3), R(3), R(1)],
[R(0), R(5, 2), R(5, 2), R(3, 2)],
[R(0), R(0), R(9), R(4)],
[R(0), R(0), R(0), R(-4, 45)]])
#print(Upper)
#print(Lower * Upper)