111
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
def Norm(x,v):
|
||||
#模 范数
|
||||
def Norm(x,v):
|
||||
if len(x[0]) == 1:
|
||||
if v == 1:
|
||||
return sum([abs(i[0]) for i in x])
|
||||
@@ -13,7 +14,7 @@ def Norm(x,v):
|
||||
return max([sum([abs(i) for i in x[j]]) for j in range(len(x))])
|
||||
return None
|
||||
|
||||
|
||||
# 计算矩阵的行列式
|
||||
def Det(A):
|
||||
if len(A) == 2:
|
||||
return A[0][0] * A[1][1] - A[0][1] * A[1][0]
|
||||
@@ -22,7 +23,7 @@ def Det(A):
|
||||
sub_matrix = [row[:c] + row[c+1:] for row in A[1:]]
|
||||
det += ((-1) ** c) * A[0][c] * Det(sub_matrix)
|
||||
return det
|
||||
|
||||
# 计算矩阵的逆矩阵
|
||||
def Inverse(A):
|
||||
n = len(A)
|
||||
# 计算代数余子式矩阵
|
||||
@@ -38,7 +39,7 @@ def Inverse(A):
|
||||
return None
|
||||
A_inv = [[B[i][j] / det for j in range(n)] for i in range(n)]
|
||||
return A_inv
|
||||
|
||||
# 计算矩阵的条件数
|
||||
def Cond(A,v):
|
||||
inv_A = Inverse(A)
|
||||
print(inv_A,Norm(A, v), Norm(inv_A, v))
|
||||
|
||||
Reference in New Issue
Block a user