Skip to content

Commit 6f644d5

Browse files
committed
changed: slightly optimize precompile.jl
1 parent 8da356f commit 6f644d5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/precompile.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,18 @@ exmpc.estim()
7979
u = exmpc([55, 30])
8080
sim!(exmpc, 2, [55, 30])
8181

82-
f(x,u,_,model) = model.A*x + model.Bu*u
83-
h(x,_,model) = model.C*x
82+
function f!(xnext, x, u, _, model)
83+
mul!(xnext, model.A , x)
84+
mul!(xnext, model.Bu, u, 1, 1)
85+
return nothing
86+
end
87+
function h!(y, x, _, model)
88+
mul!(y, model.C, x)
89+
return nothing
90+
end
8491

8592
nlmodel = setop!(
86-
NonLinModel(f, h, Ts, 2, 2, 2, solver=nothing, p=model),
93+
NonLinModel(f!, h!, Ts, 2, 2, 2, solver=nothing, p=model),
8794
uop=[10, 10], yop=[50, 30]
8895
)
8996
y = nlmodel()
@@ -118,7 +125,7 @@ u = nmpc_mhe([55, 30])
118125
sim!(nmpc_mhe, 2, [55, 30])
119126

120127
function JE( _ , Ŷe, _ , R̂y)
121-
= Ŷe[3:end]
128+
= @views Ŷe[3:end]
122129
= R̂y -
123130
return dot(Ȳ, Ȳ)
124131
end

0 commit comments

Comments
 (0)