Hello, I’ve a JuMP related question and how to use @NLexpression within a loop

mu is a JxN matrix that I’ve defined to be a variable in the MPEC model

@variable(MPEC, mu[j=1:J, n=1:N], start=mu0[j,n]).

v2 is a 5Tx100 matrix, marketStarts and marketEnds are two Tx1 arrays, “x” is a Jx5 matrix and theta2 is 5x1. I’ve tried to use different sections of v2 to calculate different values for mu, but when I run the following code

for t=1:T

v = v2[5*(t-1)+1:5*t,:];

@NLexpression(

MPEC,

mu[j=marketStarts[t]:marketStarts[t],n=1:N],

sum(theta2[k]*x[j,k]*v[k,n] for k=1:5)

)

end

the dimensions of mu change to 1xN, instead of JxN.

My question is how to do something similar to this inside @NLexpression:

mu0 = Matrix{Float64}(J,N)

for t=1:T

v = v2[5*(t-1)+1:5*t,:];

for n=1:N

for j=marketStarts[t]:marketEnds[t]

for k=1:K

mu0[j,n] += theta2[k]*x[j,k]*v[k,n]

end

end

end

end

Thank you in advance and sorry in advance if I’m not being clear enough