11"""
2- lqr(A, B, Q, R)
2+ lqr(A, B, Q, R, args...; kwargs... )
33
44Calculate the optimal gain matrix `K` for the state-feedback law `u = -K*x` that
55minimizes the cost function:
@@ -13,6 +13,9 @@ For the continuous time model `dx = Ax + Bu`.
1313Solve the LQR problem for state-space system `sys`. Works for both discrete
1414and continuous time systems.
1515
16+ The `args...; kwargs...` are sent to the Riccati solver, allowing specification of cross-covariance etc. See `?MatrixEquations.arec` for more help.
17+
18+ See also `LQG`
1619Usage example:
1720```julia
1821using LinearAlgebra # For identity matrix I
@@ -31,9 +34,8 @@ y, t, x, uout = lsim(sys,u,t,x0=x0)
3134plot(t,x', lab=["Position" "Velocity"], xlabel="Time [s]")
3235```
3336"""
34- function lqr (A, B, Q, R)
35- S = care (A, B, Q, R)
36- K = R\ B' * S
37+ function lqr (A, B, Q, R, args... ; kwargs... )
38+ S, _, K = arec (A, B, R, Q, args... ; kwargs... )
3739 return K
3840end
3941
4244 kalman(sys, R1, R2)
4345
4446Calculate the optimal Kalman gain
47+
48+ The `args...; kwargs...` are sent to the Riccati solver, allowing specification of cross-covariance etc. See `?MatrixEquations.arec/ared` for more help.
49+
50+ See also `LQG`
4551"""
46- kalman (A, C, R1,R2) = Matrix (lqr (A' ,C' ,R1,R2)' )
52+ kalman (A, C, R1,R2, args ... ; kwargs ... ) = Matrix (lqr (A' ,C' ,R1,R2, args ... ; kwargs ... )' )
4753
48- function lqr (sys:: AbstractStateSpace , Q, R)
54+ function lqr (sys:: AbstractStateSpace , Q, R, args ... ; kwargs ... )
4955 if iscontinuous (sys)
50- return lqr (sys. A, sys. B, Q, R)
56+ return lqr (sys. A, sys. B, Q, R, args ... ; kwargs ... )
5157 else
5258 return dlqr (sys. A, sys. B, Q, R)
5359 end
5460end
5561
56- function kalman (sys:: AbstractStateSpace , R1,R2 )
62+ function kalman (sys:: AbstractStateSpace , R1, R2, args ... ; kwargs ... )
5763 if iscontinuous (sys)
58- return Matrix (lqr (sys. A' , sys. C' , R1,R2)' )
64+ return Matrix (lqr (sys. A' , sys. C' , R1,R2, args ... ; kwargs ... )' )
5965 else
60- return Matrix (dlqr (sys. A' , sys. C' , R1,R2)' )
66+ return Matrix (dlqr (sys. A' , sys. C' , R1,R2, args ... ; kwargs ... )' )
6167 end
6268end
6369
6470
6571"""
66- dlqr(A, B, Q, R)
67- dlqr(sys, Q, R)
72+ dlqr(A, B, Q, R, args...; kwargs... )
73+ dlqr(sys, Q, R, args...; kwargs... )
6874
6975Calculate the optimal gain matrix `K` for the state-feedback law `u[k] = -K*x[k]` that
7076minimizes the cost function:
@@ -75,6 +81,8 @@ For the discrte time model `x[k+1] = Ax[k] + Bu[k]`.
7581
7682See also `lqg`
7783
84+ The `args...; kwargs...` are sent to the Riccati solver, allowing specification of cross-covariance etc. See `?MatrixEquations.ared` for more help.
85+
7886Usage example:
7987```julia
8088using LinearAlgebra # For identity matrix I
@@ -94,15 +102,14 @@ y, t, x, uout = lsim(sys,u,t,x0=x0)
94102plot(t,x', lab=["Position" "Velocity"], xlabel="Time [s]")
95103```
96104"""
97- function dlqr (A, B, Q, R)
98- S = dare (A, B, Q, R)
99- K = (B' * S* B + R)\ (B' S* A)
105+ function dlqr (A, B, Q, R, args... ; kwargs... )
106+ S, _, K = ared (A, B, R, Q, args... ; kwargs... )
100107 return K
101108end
102109
103- function dlqr (sys:: AbstractStateSpace , Q, R)
110+ function dlqr (sys:: AbstractStateSpace , Q, R, args ... ; kwargs ... )
104111 ! isdiscrete (sys) && throw (ArgumentError (" Input argument sys must be discrete-time system" ))
105- return dlqr (sys. A, sys. B, Q, R)
112+ return dlqr (sys. A, sys. B, Q, R, args ... ; kwargs ... )
106113end
107114
108115"""
111118
112119Calculate the optimal Kalman gain for discrete time systems
113120
121+ The `args...; kwargs...` are sent to the Riccati solver, allowing specification of cross-covariance etc. See `?MatrixEquations.ared` for more help.
114122"""
115- dkalman (A, C, R1,R2) = Matrix (dlqr (A' ,C' ,R1,R2)' )
123+ dkalman (A, C, R1,R2, args ... ; kwargs ... ) = Matrix (dlqr (A' ,C' ,R1,R2, args ... ; kwargs ... )' )
116124
117125"""
118126 place(A, B, p, opt=:c)
0 commit comments