The following formula. But $ A, Q, P \ in \ mathbb R ^ {n \ times n}, B \ in \ mathbb R ^ {n \ times m}, R \ in \ mathbb R ^ {m \ times m} $ , Q, R are definite matrix symmetric matrices, and $ A, B, Q, R $ are given to find $ P $.
It appears when finding the gain with the LQR of modern control theory. LQR is an optimal control theory, and the system
We will implement and solve the Arimoto-Potter method (explained in the next section). At that time, the eigenvalue problem of the matrix will be solved, but this uses numpy or the like.
The procedure will be explained. See books for proof.
The matrix $ H \ in \ mathbb R ^ {2n \ times 2n} $ called the Hamilton matrix
far.
There are n eigenvalues of H whose real part is negative. Place this as $ \ lambda_1, \ lambda_2, ..., \ lambda_n $ and the corresponding eigenvectors are $ \ vec w_1, \ vec w_2, ..., \ vec w_n $.
Use this to get $ Y, Z \ in \ mathbb R ^ {n \ times n} $
import numpy as np
import numpy.linalg as LA
def solve_are(A, B, Q, R):
# 1.Put the Hamilton Matrix
H = np.block([[A.T, -B @ LA.inv(R) @ B.T],
[-Q , -A]])
# 2.Eigenvalue decomposition
eigenvalue, w = LA.eig(H)
# 3.Put an auxiliary matrix
Y_, Z_ = [], []
n = len(w[0])//2
for i in range(2*n):
if eigenvalue[i].real < 0.0:
Y_.append(w.T[i][:n])
Z_.append(w.T[i][n:])
Y = np.array(Y_).T
Z = np.array(Z_).T
# 4.P is sought
return Z @ LA.inv(Y)
A = np.array([[3., 1.],[0., 1.]])
B = np.array([[1.2], [1.]])
Q = np.array([[1., 0.2], [0.2, 1.0]])
R = np.array([[1.]])
P = solve_are(A, B, Q, R)
print("P")
print(P)
print("Left side of Riccati algebraic equation")
print(A@P + [email protected] + Q - P@[email protected](R)@B.T@P)
P
[[ 69.20010326 -66.19334596]
[-66.19334596 67.7487967 ]]
Left side of Riccati algebraic equation
[[-1.13686838e-13 5.11590770e-13]
[ 2.55795385e-13 -5.68434189e-13]]
I solved it.
Recommended Posts