@@ -94,6 +94,15 @@ following fields:
9494- `:D` : measured disturbances over ``N_k``, ``\m athbf{D}``
9595- `:sol` : solution summary of the optimizer for printing
9696
97+ For [`NonLinModel`](@ref), it also includes the following derivative fields:
98+
99+ - `:JE`: economic cost value at the optimum, ``J_E``
100+ - `:gc`: custom nonlinear constraints values at the optimum, ``\m athbf{g_c}``
101+ - `:∇J` or *`:nablaJ`* : gradient of the objective function, ``\m athbf{\n abla} J``
102+ - `:∇²J` or *`:nabla2J`* : Hessian of the objective function, ``\m athbf{\n abla^2}J``
103+ - `:∇g` or *`:nablag`* : Jacobian of the inequality constraint, ``\m athbf{\n abla g}``
104+ - `:∇²ℓg` or *`:nabla2lg`* : Hessian of the inequality Lagrangian, ``\m athbf{\n abla^2}\e ll_{\m athbf{g}}``
105+
97106# Examples
98107```jldoctest
99108julia> model = LinModel(ss(1.0, 1.0, 1.0, 0, 5.0));
@@ -176,7 +185,7 @@ For [`NonLinModel`](@ref), add the various derivatives.
176185function addinfo! (
177186 info, estim:: MovingHorizonEstimator{NT} , model:: NonLinModel
178187) where NT <: Real
179- # --- derivatives ---
188+ # --- objective derivatives ---
180189 optim, con = estim. optim, estim. con
181190 nx̂, nym, nŷ, nu, nk = estim. nx̂, estim. nym, model. ny, model. nu, model. nk
182191 He = estim. He
@@ -200,6 +209,9 @@ function addinfo!(
200209 else
201210 ∇J, ∇²J = gradient (J!, estim. gradient, estim. Z̃, J_cache... ), nothing
202211 end
212+ # --- inequality constraint derivatives ---
213+ old_i_g = copy (estim. con. i_g)
214+ estim. con. i_g .= 1 # temporarily set all constraints as finite so g is entirely computed
203215 ∇g_cache = (Cache (V̂), Cache (X̂0), Cache (û0), Cache (k0), Cache (ŷ0))
204216 function g! (g, Z̃, V̂, X̂0, û0, k0, ŷ0)
205217 update_prediction! (V̂, X̂0, û0, k0, ŷ0, g, estim, Z̃)
@@ -219,6 +231,7 @@ function addinfo!(
219231 else
220232 ∇²ℓg = nothing
221233 end
234+ estim. con. i_g .= old_i_g # restore original finite/infinite constraint indices
222235 info[:∇J ] = ∇J
223236 info[:∇²J ] = ∇²J
224237 info[:∇g ] = ∇g
0 commit comments