261261Construct the prediction matrices for [`LinModel`](@ref) and [`SingleShooting`](@ref).
262262
263263The model predictions are evaluated from the deviation vectors (see [`setop!`](@ref)), the
264- decision variable ``\m athbf{Z}`` (see [`TranscriptionMethod `](@ref)), and:
264+ decision variable ``\m athbf{Z = ΔU }`` (with a [`SingleShooting `](@ref) transcription ), and:
265265```math
266266\b egin{aligned}
267267 \m athbf{Ŷ_0} &= \m athbf{E Z} + \m athbf{G d_0}(k) + \m athbf{J D̂_0}
@@ -274,7 +274,7 @@ in which ``\mathbf{x̂_0}(k) = \mathbf{x̂}_i(k) - \mathbf{x̂_{op}}``, with ``i
274274`estim.direct==true`, otherwise ``i = k - 1``. The predicted outputs ``\m athbf{Ŷ_0}`` and
275275measured disturbances ``\m athbf{D̂_0}`` respectively include ``\m athbf{ŷ_0}(k+j)`` and
276276``\m athbf{d̂_0}(k+j)`` values with ``j=1`` to ``H_p``, and input increments ``\m athbf{ΔU}``,
277- ``\m athbf{Δu}(k+j )`` from ``j =0`` to ``H_c-1``. The vector ``\m athbf{B}`` contains the
277+ ``\m athbf{Δu}(k+j_ℓ )`` from ``ℓ =0`` to ``H_c-1``. The vector ``\m athbf{B}`` contains the
278278contribution for non-zero state ``\m athbf{x̂_{op}}`` and state update ``\m athbf{f̂_{op}}``
279279operating points (for linearization at non-equilibrium point, see [`linearize`](@ref)). The
280280stochastic predictions ``\m athbf{Ŷ_s=0}`` if `estim` is not a [`InternalModel`](@ref), see
@@ -312,10 +312,10 @@ each control period ``k``, see [`initpred!`](@ref) and [`linconstraint!`](@ref).
312312 ```math
313313 \b egin{aligned}
314314 \m athbf{E} &= \b egin{bmatrix}
315- \m athbf{Q}(0, j_1, 0 ) & \m athbf{0} & \c dots & \m athbf{0} \\
316- \m athbf{Q}(j_1, j_2, 0 ) & \m athbf{Q}(j_1, j_2, j_1) & \c dots & \m athbf{0} \\
317- \v dots & \v dots & \d dots & \v dots \\
318- \m athbf{Q}(j_{H_c-1}, j_{H_c}, 0 ) & \m athbf{Q}(j_{H_c-1}, j_{H_c}, j_1) & \c dots & \m athbf{Q}(j_{H_c-1}, j_{H_c}, j_{H_c-1}) \e nd{bmatrix} \\
315+ \m athbf{Q}(j_0, j_1, j_0 ) & \m athbf{0} & \c dots & \m athbf{0} \\
316+ \m athbf{Q}(j_1, j_2, j_0 ) & \m athbf{Q}(j_1, j_2, j_1) & \c dots & \m athbf{0} \\
317+ \v dots & \v dots & \d dots & \v dots \\
318+ \m athbf{Q}(j_{H_c-1}, j_{H_c}, j_0 ) & \m athbf{Q}(j_{H_c-1}, j_{H_c}, j_1) & \c dots & \m athbf{Q}(j_{H_c-1}, j_{H_c}, j_{H_c-1}) \e nd{bmatrix} \\
319319 \m athbf{G} &= \b egin{bmatrix}
320320 \m athbf{Ĉ}\m athbf{Â}^{0} \m athbf{B̂_d} \\
321321 \m athbf{Ĉ}\m athbf{Â}^{1} \m athbf{B̂_d} \\
@@ -343,7 +343,7 @@ each control period ``k``, see [`initpred!`](@ref) and [`linconstraint!`](@ref).
343343 ```math
344344 \b egin{aligned}
345345 \m athbf{e_x̂} &= \b egin{bmatrix}
346- \m athbf{W}(H_p-1)\m athbf{B̂_u} & \m athbf{W}(H_p-j_1-1)\m athbf{B̂_u} & \c dots & \m athbf{W}(H_p-j_{H_c-1}-1)\m athbf{B̂_u} \e nd{bmatrix} \\
346+ \m athbf{W}(H_p-j_0- 1)\m athbf{B̂_u} & \m athbf{W}(H_p-j_1-1)\m athbf{B̂_u} & \c dots & \m athbf{W}(H_p-j_{H_c-1}-1)\m athbf{B̂_u} \e nd{bmatrix} \\
347347 \m athbf{g_x̂} &= \m athbf{Â}^{H_p-1} \m athbf{B̂_d} \\
348348 \m athbf{j_x̂} &= \b egin{bmatrix}
349349 \m athbf{Â}^{H_p-2}\m athbf{B̂_d} & \m athbf{Â}^{H_p-3}\m athbf{B̂_d} & \c dots & \m athbf{0} \e nd{bmatrix} \\
@@ -370,10 +370,11 @@ function init_predmat(
370370 end
371371 # Apow_csum 3D array : Apow_csum[:,:,1] = A^0, Apow_csum[:,:,2] = A^1 + A^0, ...
372372 Âpow_csum = cumsum (Âpow, dims= 3 )
373- jℓ = cumsum (nb) # introduced in move_blocking docstring
374- # three helper functions to improve code clarity and be similar to eqs. in docstring:
373+ jℓ_data = [ 0 ; cumsum (nb)] # introduced in move_blocking docstring
374+ # four helper functions to improve code clarity and be similar to eqs. in docstring:
375375 getpower (array3D, power) = @views array3D[:,:, power+ 1 ]
376- W (m) = @views Âpow_csum[:,:, m+ 1 ]
376+ W (m) = @views Âpow_csum[:,:, m+ 1 ]
377+ jℓ (ℓ) = jℓ_data[ℓ+ 1 ]
377378 function Q! (Q, i, m, b)
378379 for ℓ= 0 : m- i- 1
379380 iRows = (1 : ny) .+ ny* ℓ
@@ -396,18 +397,15 @@ function init_predmat(
396397 nZ = get_nZ (estim, transcription, Hp, Hc)
397398 ex̂ = Matrix {NT} (undef, nx̂, nZ)
398399 E = zeros (NT, Hp* ny, nZ)
399- for j= 1 : Hc
400- iCol = (1 : nu) .+ nu* (j- 1 )
401- for i= j: Hc
402- i_Q = (i == 1 && j == 1 ) ? 0 : jℓ[i- 1 ]
403- m_Q = jℓ[i]
404- b_Q = (j == 1 ) ? 0 : jℓ[j- 1 ]
405- iRow = (1 : ny* nb[i]) .+ ny* i_Q
400+ for j= 0 : Hc- 1
401+ iCol = (1 : nu) .+ nu* j
402+ for i= j: Hc- 1
403+ i_Q, m_Q, b_Q = jℓ (i), jℓ (i+ 1 ), jℓ (j)
404+ iRow = (1 : ny* nb[i+ 1 ]) .+ ny* i_Q
406405 Q = @views E[iRow, iCol]
407406 Q! (Q, i_Q, m_Q, b_Q)
408407 end
409- j_ex̂ = (j == 1 ) ? 0 : jℓ[j- 1 ]
410- ex̂[:, iCol] = W (Hp - j_ex̂ - 1 )* B̂u
408+ ex̂[:, iCol] = W (Hp - jℓ (j) - 1 )* B̂u
411409 end
412410 # --- current measured disturbances d0 and predictions D̂0 ---
413411 gx̂ = getpower (Âpow, Hp- 1 )* B̂d
@@ -453,10 +451,10 @@ They are defined in the Extended Help section.
453451 They are all appropriately sized zero matrices ``\m athbf{0}``, except for:
454452 ```math
455453 \b egin{aligned}
456- \m athbf{E} &= [\b egin{smallmatrix}\m athbf{0} & \m athbf{E^†} \e nd{smallmatrix}] \\
457- \m athbf{E^† } &= \t ext{diag}\m athbf{(Ĉ,Ĉ,...,Ĉ)} \\
458- \m athbf{J} &= \t ext{diag}\m athbf{(D̂_d,D̂_d,...,D̂_d)} \\
459- \m athbf{e_x̂} &= [\b egin{smallmatrix}\m athbf{0} & \m athbf{I}\e nd{smallmatrix}]
454+ \m athbf{E} &= [\b egin{smallmatrix}\m athbf{0} & \m athbf{E^{x̂}} \e nd{smallmatrix}] \\
455+ \m athbf{E^{x̂} } &= \t ext{diag}\m athbf{(Ĉ,Ĉ,...,Ĉ)} \\
456+ \m athbf{J} &= \t ext{diag}\m athbf{(D̂_d,D̂_d,...,D̂_d)} \\
457+ \m athbf{e_x̂} &= [\b egin{smallmatrix}\m athbf{0} & \m athbf{I}\e nd{smallmatrix}]
460458 \e nd{aligned}
461459 ```
462460"""
543541
544542Init the matrices for computing the defects over the predicted states.
545543
546- An equation similar to the prediction matrices (see
547- [`init_predmat`](@ref)) computes the defects over the predicted states:
544+ Knowing that the decision vector ``\m athbf{Z}`` contains both ``\m athbf{ΔU}`` and
545+ ``\m athbf{X̂_0}`` vectors (with a [`MultipleShooting`](@ref) transcription), an equation
546+ similar to the prediction matrices (see [`init_predmat`](@ref)) computes the defects over
547+ the predicted states:
548548```math
549549\b egin{aligned}
550550 \m athbf{Ŝ} &= \m athbf{E_ŝ Z} + \m athbf{G_ŝ d_0}(k) + \m athbf{J_ŝ D̂_0}
0 commit comments