Skip to content

Commit a1d7855

Browse files
committed
doc: clearer jℓ notation
1 parent 24a9a90 commit a1d7855

2 files changed

Lines changed: 35 additions & 29 deletions

File tree

src/controller/construct.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,17 @@ strictly positive integers):
499499
```math
500500
\mathbf{n_b} = \begin{bmatrix} n_1 & n_2 & \cdots & n_{H_c} \end{bmatrix}'
501501
```
502-
Introducing the notation ``j_ℓ = ∑_{i=1}^{ℓ} n_i`` to convert from block lengths to discrete
503-
time steps, the vector that includes all the free moves of the manipulated input is then
504-
defined as:
502+
Introducing the notation:
503+
```math
504+
j_ℓ = \begin{cases}
505+
0 & ℓ = 0 \\
506+
∑_{i=1}^{ℓ} n_i & ℓ > 0 \end{cases}
507+
```
508+
to convert from block lengths to discrete time steps, the vector that includes all the free
509+
moves of the manipulated input is then defined as:
505510
```math
506511
\mathbf{ΔU} = \begin{bmatrix}
507-
\mathbf{Δu}(k + 0) \\
512+
\mathbf{Δu}(k + j_0) \\
508513
\mathbf{Δu}(k + j_1) \\
509514
\mathbf{Δu}(k + j_2) \\
510515
\vdots \\

src/controller/transcription.jl

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ end
261261
Construct the prediction matrices for [`LinModel`](@ref) and [`SingleShooting`](@ref).
262262
263263
The model predictions are evaluated from the deviation vectors (see [`setop!`](@ref)), the
264-
decision variable ``\mathbf{Z}`` (see [`TranscriptionMethod`](@ref)), and:
264+
decision variable ``\mathbf{Z = ΔU}`` (with a [`SingleShooting`](@ref) transcription), and:
265265
```math
266266
\begin{aligned}
267267
\mathbf{Ŷ_0} &= \mathbf{E Z} + \mathbf{G d_0}(k) + \mathbf{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 ``\mathbf{Ŷ_0}`` and
275275
measured disturbances ``\mathbf{D̂_0}`` respectively include ``\mathbf{ŷ_0}(k+j)`` and
276276
``\mathbf{d̂_0}(k+j)`` values with ``j=1`` to ``H_p``, and input increments ``\mathbf{ΔU}``,
277-
``\mathbf{Δu}(k+j)`` from ``j=0`` to ``H_c-1``. The vector ``\mathbf{B}`` contains the
277+
``\mathbf{Δu}(k+j_ℓ)`` from ``=0`` to ``H_c-1``. The vector ``\mathbf{B}`` contains the
278278
contribution for non-zero state ``\mathbf{x̂_{op}}`` and state update ``\mathbf{f̂_{op}}``
279279
operating points (for linearization at non-equilibrium point, see [`linearize`](@ref)). The
280280
stochastic predictions ``\mathbf{Ŷ_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
\begin{aligned}
314314
\mathbf{E} &= \begin{bmatrix}
315-
\mathbf{Q}(0, j_1, 0) & \mathbf{0} & \cdots & \mathbf{0} \\
316-
\mathbf{Q}(j_1, j_2, 0) & \mathbf{Q}(j_1, j_2, j_1) & \cdots & \mathbf{0} \\
317-
\vdots & \vdots & \ddots & \vdots \\
318-
\mathbf{Q}(j_{H_c-1}, j_{H_c}, 0) & \mathbf{Q}(j_{H_c-1}, j_{H_c}, j_1) & \cdots & \mathbf{Q}(j_{H_c-1}, j_{H_c}, j_{H_c-1}) \end{bmatrix} \\
315+
\mathbf{Q}(j_0, j_1, j_0) & \mathbf{0} & \cdots & \mathbf{0} \\
316+
\mathbf{Q}(j_1, j_2, j_0) & \mathbf{Q}(j_1, j_2, j_1) & \cdots & \mathbf{0} \\
317+
\vdots & \vdots & \ddots & \vdots \\
318+
\mathbf{Q}(j_{H_c-1}, j_{H_c}, j_0) & \mathbf{Q}(j_{H_c-1}, j_{H_c}, j_1) & \cdots & \mathbf{Q}(j_{H_c-1}, j_{H_c}, j_{H_c-1}) \end{bmatrix} \\
319319
\mathbf{G} &= \begin{bmatrix}
320320
\mathbf{Ĉ}\mathbf{Â}^{0} \mathbf{B̂_d} \\
321321
\mathbf{Ĉ}\mathbf{Â}^{1} \mathbf{B̂_d} \\
@@ -343,7 +343,7 @@ each control period ``k``, see [`initpred!`](@ref) and [`linconstraint!`](@ref).
343343
```math
344344
\begin{aligned}
345345
\mathbf{e_x̂} &= \begin{bmatrix}
346-
\mathbf{W}(H_p-1)\mathbf{B̂_u} & \mathbf{W}(H_p-j_1-1)\mathbf{B̂_u} & \cdots & \mathbf{W}(H_p-j_{H_c-1}-1)\mathbf{B̂_u} \end{bmatrix} \\
346+
\mathbf{W}(H_p-j_0-1)\mathbf{B̂_u} & \mathbf{W}(H_p-j_1-1)\mathbf{B̂_u} & \cdots & \mathbf{W}(H_p-j_{H_c-1}-1)\mathbf{B̂_u} \end{bmatrix} \\
347347
\mathbf{g_x̂} &= \mathbf{Â}^{H_p-1} \mathbf{B̂_d} \\
348348
\mathbf{j_x̂} &= \begin{bmatrix}
349349
\mathbf{Â}^{H_p-2}\mathbf{B̂_d} & \mathbf{Â}^{H_p-3}\mathbf{B̂_d} & \cdots & \mathbf{0} \end{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,16 @@ 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+
ni = nb[i+1]
405+
iRow = (1:ny*ni) .+ ny*i_Q
406406
Q = @views E[iRow, iCol]
407407
Q!(Q, i_Q, m_Q, b_Q)
408408
end
409-
j_ex̂ = (j == 1) ? 0 : jℓ[j-1]
410-
ex̂[:, iCol] = W(Hp - j_ex̂ - 1)*B̂u
409+
ex̂[:, iCol] = W(Hp - jℓ(j) - 1)*B̂u
411410
end
412411
# --- current measured disturbances d0 and predictions D̂0 ---
413412
gx̂ = getpower(Âpow, Hp-1)*B̂d
@@ -453,10 +452,10 @@ They are defined in the Extended Help section.
453452
They are all appropriately sized zero matrices ``\mathbf{0}``, except for:
454453
```math
455454
\begin{aligned}
456-
\mathbf{E} &= [\begin{smallmatrix}\mathbf{0} & \mathbf{E^†} \end{smallmatrix}] \\
457-
\mathbf{E^} &= \text{diag}\mathbf{(Ĉ,Ĉ,...,Ĉ)} \\
458-
\mathbf{J} &= \text{diag}\mathbf{(D̂_d,D̂_d,...,D̂_d)} \\
459-
\mathbf{e_x̂} &= [\begin{smallmatrix}\mathbf{0} & \mathbf{I}\end{smallmatrix}]
455+
\mathbf{E} &= [\begin{smallmatrix}\mathbf{0} & \mathbf{E^{x̂}} \end{smallmatrix}] \\
456+
\mathbf{E^{x̂}} &= \text{diag}\mathbf{(Ĉ,Ĉ,...,Ĉ)} \\
457+
\mathbf{J} &= \text{diag}\mathbf{(D̂_d,D̂_d,...,D̂_d)} \\
458+
\mathbf{e_x̂} &= [\begin{smallmatrix}\mathbf{0} & \mathbf{I}\end{smallmatrix}]
460459
\end{aligned}
461460
```
462461
"""
@@ -543,8 +542,10 @@ end
543542
544543
Init the matrices for computing the defects over the predicted states.
545544
546-
An equation similar to the prediction matrices (see
547-
[`init_predmat`](@ref)) computes the defects over the predicted states:
545+
Knowing that the decision vector ``\mathbf{Z}`` contains both ``\mathbf{ΔU}`` and
546+
``\mathbf{X̂_0}`` vectors (with a [`MultipleShooting`](@ref) transcription), an equation
547+
similar to the prediction matrices (see [`init_predmat`](@ref)) computes the defects over
548+
the predicted states:
548549
```math
549550
\begin{aligned}
550551
\mathbf{Ŝ} &= \mathbf{E_ŝ Z} + \mathbf{G_ŝ d_0}(k) + \mathbf{J_ŝ D̂_0}

0 commit comments

Comments
 (0)