111
This commit is contained in:
21
227-3.py
21
227-3.py
@@ -1,10 +1,3 @@
|
||||
A = [
|
||||
[0, 3, 4],
|
||||
[1, -1, 1],
|
||||
[2, 1, 2]
|
||||
]
|
||||
|
||||
b = [1, 2, 3]
|
||||
|
||||
# 列主元高斯消元法
|
||||
def SovleRowMain(A,b):
|
||||
@@ -61,7 +54,7 @@ def SovleRowMain(A,b):
|
||||
|
||||
P[i][p[i]] = 1
|
||||
return P,L,U,b
|
||||
|
||||
#打印矩阵
|
||||
def prettyPrintMatrix(matrix):
|
||||
for row in matrix:
|
||||
print(row)
|
||||
@@ -70,6 +63,15 @@ def prettyPrintMatrix(matrix):
|
||||
if __name__ == "__main__":
|
||||
# A = np.array(A, dtype=float)
|
||||
# b = np.array(b, dtype=float)
|
||||
|
||||
A = [
|
||||
[0, 3, 4],
|
||||
[1, -1, 1],
|
||||
[2, 1, 2]
|
||||
]
|
||||
|
||||
b = [1, 2, 3]
|
||||
|
||||
P,L,U,x = SovleRowMain(A, b)
|
||||
print("P:")
|
||||
prettyPrintMatrix(P)
|
||||
@@ -79,4 +81,5 @@ if __name__ == "__main__":
|
||||
prettyPrintMatrix(U)
|
||||
print("x:")
|
||||
print(x)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user