可控性
#A为系统状态矩阵 B为控制输入矩阵
def kekong(A,B):
AB={}
AB[0]=B
for i in range(1,A.shape[0]):
AB[i]=A.dot(AB[i-1])
q=np.column_stack((AB.values()))
print("系数矩阵为:",q)
#保证非奇异性
z=q.dot(q.T)
print(z)
if np.linalg.det(z)!=0:
print("非奇异矩阵,行列式为:",np.linalg.det(z))
else:
print( "奇异矩阵行列式为:",np.linalg.det(z))
print("矩阵的秩为",np.linalg.matrix_rank(q))
if np.linalg.matrix_rank(z)!=A.shape[0]:
print("矩阵不可控")
else:
print("矩阵可控")
return np.linalg.matrix_rank(z)
可观性
def keguan(A,C):
AC={}
AC[0]=C
for i in range(1,A.shape[0]):
AC[i]=AC[i-1].dot(A)
print(AC.values())
q=np.row_stack((AC.values()))
print("系数矩阵为:",q)
#保证非奇异性
z=q.dot(q.T)
print(z)
if np.linalg.det(z)!=0:
print("非奇异矩阵,行列式为:",np.linalg.det(z))
else:
print( "奇异矩阵行列式为:",np.linalg.det(z))
print("矩阵的秩为",np.linalg.matrix_rank(q))
if np.linalg.matrix_rank(z)!=A.shape[0]:
print("矩阵不可观")
else:
print("矩阵可观")
return np.linalg.matrix_rank(z)