141141init_ZtoU_Smat ( _ , transcription:: SingleShooting , _ , _ , Sdagger) = Sdagger
142142
143143function init_ZtoU_Smat (estim, transcription:: MultipleShooting , Hp, _ , Sdagger)
144- return [Sdagger; zeros (eltype (Sdagger), estim. model. nu* Hp, estim. nx̂* Hp)]
144+ return [Sdagger zeros (eltype (Sdagger), estim. model. nu* Hp, estim. nx̂* Hp)]
145145end
146146
147147@doc raw """
@@ -326,8 +326,10 @@ function init_predmat(
326326 nu, nx̂, ny, nd = model. nu, estim. nx̂, model. ny, model. nd
327327 # --- state estimates x̂ ---
328328 K = zeros (NT, Hp* ny, nx̂)
329+ kx̂ = zeros (NT, nx̂, nx̂)
329330 # --- manipulated inputs u ---
330331 V = zeros (NT, Hp* ny, nu)
332+ vx̂ = zeros (NT, nx̂, nu)
331333 # --- decision variables Z ---
332334 E = [zeros (NT, Hp* ny, Hc* nu) repeatdiag (Ĉ, Hp)]
333335 ex̂ = [zeros (NT, nx̂, Hc* nu + (Hp- 1 )* nx̂) I]
@@ -338,7 +340,7 @@ function init_predmat(
338340 jx̂ = zeros (NT, nx̂, Hp* nd)
339341 # --- state x̂op and state update f̂op operating points ---
340342 B = zeros (NT, Hp* ny, 1 )
341- bx̂ = zeros (NT, nx̂, 1 )
343+ bx̂ = zeros (NT, nx̂)
342344 return E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂
343345end
344346
@@ -377,7 +379,7 @@ function init_predmat(
377379 V = zeros (NT, 0 , nu)
378380 B = zeros (NT, 0 )
379381 ex̂ = [zeros (NT, nx̂, Hc* nu + (Hp- 1 )* nx̂) I]
380- gx̂, jx̂, kx̂, vx̂, bx̂ = E, G, J, K, V
382+ gx̂, jx̂, kx̂, vx̂, bx̂ = E, G, J, K, V, B
381383 return E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂
382384end
383385
@@ -423,23 +425,23 @@ matrices ``\mathbf{E_ŝ, G_ŝ, J_ŝ, K_ŝ, V_ŝ, B_ŝ}`` are defined in th
423425 ```math
424426 \b egin{aligned}
425427 \m athbf{E_ŝ} &= \b egin{bmatrix}
426- \m athbf{B̂_u} & \m athbf{0} & \c dots & \m athbf{0} & -\m athbf{I} & \m athbf{0} & \c dots & \m athbf{0} \\
427- \m athbf{B̂_u} & \m athbf{B̂_u} & \c dots & \m athbf{0} & \m athbf{Â} & -\m athbf{I} & \c dots & \m athbf{0} \\
428- \v dots & \v dots & \d dots & \v dots & \v dots & \v dots & \d dots & \v dots \\
429- \m athbf{B̂_u} & \m athbf{B̂_u} & \c dots & \m athbf{B̂_u} & \m athbf{0} & \m athbf{0} & \c dots & -\m athbf{I} \e nd{bmatrix} \\
428+ \m athbf{B̂_u} & \m athbf{0} & \c dots & \m athbf{0} & -\m athbf{I} & \m athbf{0} & \c dots & \m athbf{0} \\
429+ \m athbf{B̂_u} & \m athbf{B̂_u} & \c dots & \m athbf{0} & \m athbf{Â} & -\m athbf{I} & \c dots & \m athbf{0} \\
430+ \v dots & \v dots & \d dots & \v dots & \v dots & \v dots & \d dots & \v dots \\
431+ \m athbf{B̂_u} & \m athbf{B̂_u} & \c dots & \m athbf{B̂_u} & \m athbf{0} & \m athbf{0} & \c dots & -\m athbf{I} \e nd{bmatrix} \\
430432 \m athbf{G_ŝ} &= \b egin{bmatrix}
431- \m athbf{B̂_d} \\ \m athbf{0} \\ \v dots \\ \m athbf{0} \e nd{bmatrix} \\
433+ \m athbf{B̂_d} \\ \m athbf{0} \\ \v dots \\ \m athbf{0} \e nd{bmatrix} \\
432434 \m athbf{J_ŝ} &= \b egin{bmatrix}
433- \m athbf{0} & \m athbf{0} & \c dots & \m athbf{0} & \m athbf{0} \\
434- \m athbf{B̂_d} & \m athbf{0} & \c dots & \m athbf{0} & \m athbf{0} \\
435- \v dots & \v dots & \d dots & \v dots & \v dots \\
436- \m athbf{0} & \m athbf{0} & \c dots & \m athbf{B̂_d} & \m athbf{0} \e nd{bmatrix} \\
435+ \m athbf{0} & \m athbf{0} & \c dots & \m athbf{0} & \m athbf{0} \\
436+ \m athbf{B̂_d} & \m athbf{0} & \c dots & \m athbf{0} & \m athbf{0} \\
437+ \v dots & \v dots & \d dots & \v dots & \v dots \\
438+ \m athbf{0} & \m athbf{0} & \c dots & \m athbf{B̂_d} & \m athbf{0} \e nd{bmatrix} \\
437439 \m athbf{K_ŝ} &= \b egin{bmatrix}
438- \m athbf{Â} \\ \m athbf{0} \\ \v dots \\ \m athbf{0} \e nd{bmatrix} \\
440+ \m athbf{Â} \\ \m athbf{0} \\ \v dots \\ \m athbf{0} \e nd{bmatrix} \\
439441 \m athbf{V_ŝ} &= \b egin{bmatrix}
440- \m athbf{B̂_u} \\ \m athbf{B̂_u} \\ \v dots \\ \m athbf{B̂_u} \e nd{bmatrix} \\
442+ \m athbf{B̂_u} \\ \m athbf{B̂_u} \\ \v dots \\ \m athbf{B̂_u} \e nd{bmatrix} \\
441443 \m athbf{B_ŝ} &= \b egin{bmatrix}
442- \m athbf{f̂_{op} - x̂_{op}} \\ \m athbf{f̂_{op} - x̂_{op}} \\ \v dots \\ \m athbf{f̂_{op} - x̂_{op}} \e nd{bmatrix}
444+ \m athbf{f̂_{op} - x̂_{op}} \\ \m athbf{f̂_{op} - x̂_{op}} \\ \v dots \\ \m athbf{f̂_{op} - x̂_{op}} \e nd{bmatrix}
443445 \e nd{aligned}
444446 ```
445447"""
@@ -453,13 +455,18 @@ function init_defectmat(
453455 # --- manipulated inputs u ---
454456 Vŝ = repeat (B̂u, Hp)
455457 # --- decision variables Z ---
456- nI_nu = Matrix {NT} (- I, nu, nu)
457- Eŝ = [LowerTriangular (repeat (B̂u, Hc, Hc)) repeatdiag (nI_nu, Hp)]
458+ nI_nx̂ = Matrix {NT} (- I, nx̂, nx̂)
459+ Eŝ = [zeros (nx̂* Hp, nu* Hc) repeatdiag (nI_nx̂, Hp)]
460+ for j= 1 : Hc, i= j: Hp
461+ iRow = (1 : nx̂) .+ nx̂* (i- 1 )
462+ iCol = (1 : nu) .+ nu* (j- 1 )
463+ Eŝ[iRow, iCol] = B̂u
464+ end
458465 # --- measured disturbances d ---
459466 Gŝ = [B̂d; zeros (NT, (Hp- 1 )* nx̂, nd)]
460- Jŝ = [zeros (NT, nx̂, Hp * nd ); repeatdiag (B̂d, Hp- 1 ) zeros (NT, (Hp- 1 )* nd , nd)]
467+ Jŝ = [zeros (nx̂, nd * Hp ); repeatdiag (B̂d, Hp- 1 ) zeros (NT, nx̂ * (Hp- 1 ), nd)]
461468 # --- state x̂op and state update f̂op operating points ---
462- B̂s = repeat (estim. f̂op - estim. x̂op, Hp)
469+ Bŝ = repeat (estim. f̂op - estim. x̂op, Hp)
463470 return Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ
464471end
465472
0 commit comments