Skip to content

Commit 441ad61

Browse files
committed
added: implementing new 3-args Q! function
1 parent 01d0410 commit 441ad61

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

src/controller/transcription.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,14 @@ function init_predmat(
373373
# three helper functions to improve code clarity and be similar to eqs. in docstring:
374374
getpower(array3D, power) = @views array3D[:,:, power+1]
375375
W(m) = @views Âpow_csum[:,:, m+1]
376-
function Q!(Q, i, j)
377-
for=1:j
378-
iRows = (1:ny) .+ ny*(ℓ-1)
379-
Q[iRows, :] =*W(i+-1)*B̂u
376+
function Q!(Q, i, k, b)
377+
for=0:k-i-1
378+
iRows = (1:ny) .+ ny*
379+
Q[iRows, :] = * W(i-b+ℓ) * B̂u
380380
end
381381
return Q
382382
end
383+
jℓ = cumsum(nb)
383384
# --- current state estimates x̂0 ---
384385
kx̂ = getpower(Âpow, Hp)
385386
K = Matrix{NT}(undef, Hp*ny, nx̂)
@@ -390,27 +391,28 @@ function init_predmat(
390391
# --- previous manipulated inputs lastu0 ---
391392
vx̂ = W(Hp-1)*B̂u
392393
V = Matrix{NT}(undef, Hp*ny, nu)
393-
Q!(V, 0, Hp)
394+
Q!(V, 0, Hp, 0)
394395
# --- decision variables Z ---
395396
nZ = get_nZ(estim, transcription, Hp, Hc)
396397
ex̂ = Matrix{NT}(undef, nx̂, nZ)
397398
E = zeros(NT, Hp*ny, nZ)
398399
for j=1:Hc
399400
iCol = (1:nu) .+ nu*(j-1)
400-
for i=1:Hc-j+1
401-
i_Q = i > 1 ? nb[i-1] : 0
402-
@show i
403-
j_Q = nb[i + j - 1]
404-
iRow = (1:ny*j_Q) .+ ny*sum(nb[1:i+j-2])
401+
for i=j:Hc
402+
@show i, j
403+
i_Q = (i == 1 && j == 1) ? 0 : jℓ[i-1]
404+
k_Q = jℓ[i]
405+
b_Q = (j == 1) ? 0 : jℓ[j-1]
406+
iRow = (1:ny*nb[i]) .+ ny*i_Q
407+
@show iRow
405408
Q = @views E[iRow, iCol]
406-
Q!(Q, i_Q, j_Q)
407-
@show i_Q, j_Q
409+
Q!(Q, i_Q, k_Q, b_Q)
408410
end
409-
n = j > 1 ? nb[j-1] : 0
410-
ex̂[: , iCol] = W(Hp-n-1)*B̂u
411+
j_ex̂ = (j == 1) ? 0 : jℓ[j-1]
412+
ex̂[: , iCol] = W(Hp - j_ex̂ - 1)*B̂u
411413
end
412414

413-
#display(E)
415+
display(E)
414416

415417

416418
# --- current measured disturbances d0 and predictions D̂0 ---

0 commit comments

Comments
 (0)