|
74 | 74 |
|
75 | 75 | Init stochastic model matrices from integrator specifications for state estimation. |
76 | 76 |
|
| 77 | +The arguments `nint_u` and `nint_ym` specify how many integrators are added to each |
| 78 | +manipulated input and measured outputs. The function returns the state-space matrices `As`, |
| 79 | +`Cs_u` and `Cs_y` of the stochastic model: |
77 | 80 | ```math |
78 | | -\mathbf{} |
| 81 | +\begin{aligned} |
| 82 | +\mathbf{x_s}(k+1) &= \mathbf{A_s x_s}(k) + \mathbf{B_s e}(k) \\ |
| 83 | +\mathbf{y_s_{u}}(k) &= \mathbf{C_s_{u} x_s}(k) \\ |
| 84 | +\mathbf{y_s_{ym}}(k) &= \mathbf{C_s_{ym} x_s}(k) \\ |
| 85 | +\end{aligned} |
79 | 86 | ``` |
80 | | -
|
81 | | -The function [`init_integrators`](@ref) builds the state-space matrice of the unmeasured |
82 | | -disturbance models. |
| 87 | +where ``\mathbf{e}(k)`` is an unknown zero mean white noise and ``\mathbf{A_s} = |
| 88 | +\mathrm{diag}(\mathbf{A_s_{u}, A_s_{ym}})``. The estimations does not use ``\mathbf{B_s}``, |
| 89 | +it is thus ignored. The function [`init_integrators`](@ref) builds the state-space matrices. |
83 | 90 | """ |
84 | 91 | function init_estimstoch(model, i_ym, nint_u::IntVectorOrInt, nint_ym::IntVectorOrInt) |
85 | 92 | nu, ny, nym = model.nu, model.ny, length(i_ym) |
@@ -120,50 +127,44 @@ function stoch_ym2y(model::SimModel, i_ym, Asm, Bsm, Csm, Dsm) |
120 | 127 | end |
121 | 128 |
|
122 | 129 | @doc raw""" |
123 | | - init_integrators(nint, nys, varname::String) -> As, Cs, nint |
| 130 | + init_integrators(nint, ny, varname::String) -> A, C, nint |
124 | 131 |
|
125 | | -Calc state-space matrices `As, Cs` (stochastic part) from integrator specifications `nint`. |
| 132 | +Calc `A, C` state-space matrices from integrator specifications `nint`. |
126 | 133 |
|
127 | 134 | This function is used to initialize the stochastic part of the augmented model for the |
128 | 135 | design of state estimators. The vector `nint` provides how many integrators (in series) |
129 | | -should be incorporated for each stochastic output ``\mathbf{y_s}``: |
130 | | -```math |
131 | | -\begin{aligned} |
132 | | -\mathbf{x_s}(k+1) &= \mathbf{A_s x_s}(k) + \mathbf{B_s e}(k) \\ |
133 | | -\mathbf{y_s}(k) &= \mathbf{C_s x_s}(k) |
134 | | -\end{aligned} |
135 | | -``` |
136 | | -where ``\mathbf{e}(k)`` is an unknown zero mean white noise. The specific case of one |
137 | | -integrator per stochastic output results in `A_s = I` and `C_s = I`. The estimations does |
138 | | -not use ``\mathbf{B_s}``, it is thus ignored. Note that this function is called twice : |
| 136 | +should be incorporated for each output. The argument should have `ny` element, except |
| 137 | +for `nint=0` which is an alias for no integrator at all. The specific case of one integrator |
| 138 | +per output results in `A = I` and `C = I`. The estimation does not use the `B` matrix, it |
| 139 | +is thus ignored. This function is called twice : |
139 | 140 |
|
140 | 141 | 1. for the unmeasured disturbances at manipulated inputs ``\mathbf{u}`` |
141 | 142 | 2. for the unmeasured disturbances at measured outputs ``\mathbf{y^m}`` |
142 | 143 | """ |
143 | | -function init_integrators(nint::IntVectorOrInt, nys, varname::String) |
| 144 | +function init_integrators(nint::IntVectorOrInt, ny, varname::String) |
144 | 145 | if nint == 0 # alias for no integrator at all |
145 | | - nint = fill(0, nys) |
| 146 | + nint = fill(0, ny) |
146 | 147 | end |
147 | | - if length(nint) ≠ nys |
148 | | - error("nint_$(varname) size ($(length(nint))) ≠ n$(varname) ($nys)") |
| 148 | + if length(nint) ≠ ny |
| 149 | + error("nint_$(varname) size ($(length(nint))) ≠ n$(varname) ($ny)") |
149 | 150 | end |
150 | 151 | any(nint .< 0) && error("nint_$(varname) values should be ≥ 0") |
151 | | - nxs = sum(nint) |
152 | | - As, Cs = zeros(nxs, nxs), zeros(nys, nxs) |
153 | | - if nxs ≠ 0 # construct stochastic model state-space matrices (integrators) : |
154 | | - i_As, i_Cs = 1, 1 |
155 | | - for i = 1:nys |
| 152 | + nx = sum(nint) |
| 153 | + A, C = zeros(nx, nx), zeros(ny, nx) |
| 154 | + if nx ≠ 0 |
| 155 | + i_A, i_C = 1, 1 |
| 156 | + for i = 1:ny |
156 | 157 | nint_i = nint[i] |
157 | 158 | if nint_i ≠ 0 |
158 | | - rows_As = (i_As):(i_As + nint_i - 1) |
159 | | - As[rows_As, rows_As] = Bidiagonal(ones(nint_i), ones(nint_i-1), :L) |
160 | | - Cs[i, i_Cs+nint_i-1] = 1 |
161 | | - i_As += nint_i |
162 | | - i_Cs += nint_i |
| 159 | + rows_A = (i_A):(i_A + nint_i - 1) |
| 160 | + A[rows_A, rows_A] = Bidiagonal(ones(nint_i), ones(nint_i-1), :L) |
| 161 | + C[i, i_C+nint_i-1] = 1 |
| 162 | + i_A += nint_i |
| 163 | + i_C += nint_i |
163 | 164 | end |
164 | 165 | end |
165 | 166 | end |
166 | | - return As, Cs, nint |
| 167 | + return A, C, nint |
167 | 168 | end |
168 | 169 |
|
169 | 170 | @doc raw""" |
|
0 commit comments