Let's say that I have this equation. This is the Riccati Differential Equation:
$$P A + A^T P - P B R^{-1} B^T P + Q = 0$$
I know $ A, B, Q, R$. My goal is to find $P$. How do I use the MATLAB / Octave command fsolve to find $P$ ?
EDIT: $$ $$
Here is the answer - An example to get LQR matrix.
>> fun = @(P, A, B, Q, R) P*A+A'*P-P*B*inv(R)*B'*P + Q
fun =
@(P, A, B, Q, R) P * A + A' * P - P * B * inv (R) * B' * P + Q
>> p0 = 0.1*ones(2)
p0 =
0.10000 0.10000
0.10000 0.10000
>> P = fsolve(@(P) fun(P, Amat, Bmat, Q, R), p0)
P =
55.67637 0.57241
0.57241 2.29935
>>
>> inv(R)*Bmat'*P
ans =
2.2269e-02 2.2895e-04
-1.4350e-03 -5.7645e-03
>> lqr(Amat, Bmat, Q, R)
ans =
2.2269e-02 2.2899e-04
-1.4353e-03 -5.7644e-03
>>
Define a function, demofun:
Then write the script that optimizes the function