1.非奇异矩阵(即可逆矩阵)的最简单判断方式便是计算其行列式是否为0。
python代码实现如下:
import numpy as np
L = np.array([[0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 1],[1, 0, 0, 0]], dtype=int)
det_L = np.linalg.det(L)
if det_L != 0:
print("矩阵 L 是非奇异矩阵")
else:
print("矩阵 L 是奇异矩阵")
L_2 = np.dot(L,L)
2.非奇异矩阵的判断还可以利用矩阵是否满秩来判断
import numpy as np
def is_nonsingular(matrix):
rank = np.linalg.matrix_rank(matrix)
rows, cols = matrix.shape
if rank == min(rows, cols):
return True
else:
return False
# 示例用法
matrix = np.array([[1, 2], [3, 4]])
print(is_nonsingular(matrix)) # 输出True
matrix = np.array([[1, 2], [2, 4]])
print(is_nonsingular(matrix)) # 输出False