-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestScript.py
65 lines (54 loc) · 1.85 KB
/
testScript.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
from matrix.models import Matrix
'''
Ax = B
A = a_matrix
B = b_matrix
'''
a_matrix = ["zad1_a.txt", "zad2_a.txt", "zad3_a.txt", "zad4_a.txt", "zad5_a.txt"]
b_matrix = ["zad1_b.txt", "zad2_b.txt", "zad3_b.txt", "zad4_b.txt", "zad5_b.txt"]
for i in range(0, len(a_matrix)):
"""
For all matrices calculate LU, LUP, forward and backward substitution
"""
try:
matrix = Matrix.fromtextfile("./test_files/" + a_matrix[i])
b = Matrix.fromtextfile("./test_files/" + b_matrix[i])
except FileNotFoundError:
print("Missing file/s {}, {}...\n".format(a_matrix[i], b_matrix[i]))
continue
print("\n\n**********{} + {}**********\n".format(a_matrix[i], b_matrix[i]))
try:
print("############LU:############")
matrix.lu()
print("A:")
print(str(matrix))
matrix.forward_substitution(b)
print("\n############LU: Forward substitution:####")
print("Y:")
print(str(b))
matrix.back_substitution(b)
print("\n############LU: Backward substitution:####")
print("X:")
print(str(b))
print("############END############\n\n")
except Exception as err:
print(err)
try:
# Reload matrices
matrix = Matrix.fromtextfile("./test_files/" + a_matrix[i])
b = Matrix.fromtextfile("./test_files/" + b_matrix[i])
print("############LUP:############")
matrix.lup()
print("A:")
print(str(matrix))
matrix.forward_substitution(b)
print("\n############LUP: Forward substitution:############")
print("Y:")
print(str(b))
matrix.back_substitution(b)
print("\n############LUP: Backward substitution:############")
print("X:")
print(str(b))
print("############END############\n\n")
except Exception as err:
print(err)