# Dynamic expreesion name in JuMP

Hi All,
is there a way to create dynamic expression name in Julia? like the code given below Julia 1.2

``````mod2=Model()
@variable(mod2,x[ i in 1:13])
@variable(mod2,y[ i in 1:13])
@constraint(mod2, [i in 1:13], x[i]+y[i]>=30)
for i in 1:13
temp\$i=    @expression(mod2,x[i]+y[i]+3)
@constraint(mod2,temp\$i<=100)
end
print(mod2)

Thanks``````

Can you use a Julia container?

``````temp = Array{AffExpr}(undef, 13)
for i in 1:13
temp[i] = @expression(mod2,x[i]+y[i]+3)
end

@constraint(mod2, [i=1:13], temp[i] <= 100)
``````
2 Likes
``````mod2=Model()
@variable(mod2,x[ i in 1:13])
@variable(mod2,y[ i in 1:13])
@constraint(mod2, [i in 1:13], x[i]+y[i]>=30)

temp = Vector{Any}(undef, 13)
for i in 1:13
temp[i]=    @expression(mod2,x[i]+y[i]+3)
end
@constraint(mod2,temp .<= 100)

print(mod2)
``````
1 Like

1 Like

EDIT(odow): this was asked as a separate question: Dynamic NL expression in julia

Hi, I am using Juniper to solve MNILP and with array of nonlinear expression i am getting invalid model error. is there a way to generate nonlinear expression names in a loop like

``````@variable(model,x)
zz=0.0
for i in 1:5
for j in 1:5
global zz=zz+1
println(zz)
xmm_\$zz=@NLexpression(model,x+x*x+zz)
end
end
println(model)``````