Skip to content

Commit 3b8a297

Browse files
committed
add full alternative in dare3
1 parent 94692e7 commit 3b8a297

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RobustAndOptimalControl"
22
uuid = "21fd56a4-db03-40ee-82ee-a87907bee541"
33
authors = ["Fredrik Bagge Carlson", "Marcus Greiff"]
4-
version = "0.4.4"
4+
version = "0.4.5"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/lqg.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,24 @@ function lqr3(P::AbstractStateSpace{<:Discrete}, Q1::AbstractMatrix, Q2::Abstrac
183183
end
184184

185185
"""
186-
dare3(P::AbstractStateSpace, Q1::AbstractMatrix, Q2::AbstractMatrix, Q3::AbstractMatrix)
186+
dare3(P::AbstractStateSpace, Q1::AbstractMatrix, Q2::AbstractMatrix, Q3::AbstractMatrix; full=false)
187187
188188
Solve the discrete-time algebraic Riccati equation for a discrete LQR cost augmented with control differences
189189
```math
190190
x^{T} Q_1 x + u^{T} Q_2 u + Δu^{T} Q_3 Δu, \\quad
191191
Δu = u(k) - u(k-1)
192192
```
193+
If `full`, the returned matrix will include the state `u(k-1)`, otherwise the returned matrix will be of the same size as `Q1`.
193194
"""
194-
function dare3(P::AbstractStateSpace{<:Discrete}, Q1::AbstractMatrix, Q2::AbstractMatrix, Q3::AbstractMatrix)
195+
function dare3(P::AbstractStateSpace{<:Discrete}, Q1::AbstractMatrix, Q2::AbstractMatrix, Q3::AbstractMatrix; full=false)
195196
# The reference cited in MatrixEquations.ared, W.F. Arnold, III and A.J. Laub, Generalized Eigenproblem Algorithms and Software for Algebraic Riccati Equations
196197
# defines the cost function as x'Q1x + u'Q2u + 2x'Su.
197198
# The Δu term expands to u+'Q2u + u'Q2u - 2u Q3 u+, so the factor 2 is already accounted for
198199
Pd = add_input_differentiator(P)
199200
S = zeros(Pd.nx, P.nu)
200201
S[P.nx+1:end, :] = -Q3
201202
X, _, L = MatrixEquations.ared(Pd.A, Pd.B, Q2+Q3, cat(Q1, Q3, dims=(1,2)), S) # ME has cost matrices reversed
202-
X[1:P.nx, 1:P.nx]
203+
full ? X : X[1:P.nx, 1:P.nx]
203204
end
204205

205206
dare3(A::AbstractMatrix, B, Q1, Q2, Q3::AbstractMatrix) = dare3(ss(A, B, I(size(A,1)), 0, 1), Q1, Q2, Q3)

0 commit comments

Comments
 (0)