Skip to content

Commit cfa2136

Browse files
committed
let block for closures
1 parent 8235951 commit cfa2136

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

example/juMPC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ setconstraint!(mpc, ŷmin=[-Inf,-Inf], ŷmax=[55, 35])
9595
setconstraint!(mpc, Δumin=[-Inf,-Inf],Δumax=[+Inf,+Inf])
9696

9797
function test_mpc(model, mpc)
98-
N = 200
98+
N = 20000
9999
u_data = zeros(2,N)
100100
y_data = zeros(2,N)
101101
r_data = zeros(2,N)

src/sim_model.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ function LinModel(
161161
C = sys_dis.C;
162162
Dd = sys_dis.D[:,nu+1:end]
163163
# the `let` block captures and fixes A, Bu, Bd, C, Dd values (faster computations):
164-
f = (x,u,d) -> A*x + Bu*u + Bd*d
165-
h = (x,d) -> C*x + Dd*d
164+
f = let A=A, Bu=Bu, Bd=Bd
165+
(x, u, d) -> A*x + Bu*u + Bd*d
166+
end
167+
h = let C=C, Dd=Dd
168+
(x, d) -> C*x + Dd*d
169+
end
166170
return LinModel_ssfunc(A, Bu, C, Bd, Dd, f, h, Ts, nu, nx, ny, nd)
167171
end
168172

0 commit comments

Comments
 (0)