Hi, I’m trying to create a quadratic expression using a variable attached in model m :

using JuMP
using Ipopt
m= Model(with_optimizer(Ipopt.Optimizer))
@variables m begin
u[1:(time_lapses)*2,1:number_of_players]
end
cf=@expression(m,[1:(time_lapses*2),1:number_of_players],0)
for i in 1:number_of_prosumers
for j in 1:(time_lapses*2)
cf[j,i]=u[j,i]*u[j,i]
end
end

I get this error :

MethodError: Cannot `convert` an object of type GenericQuadExpr{Float64,VariableRef} to an object of type GenericAffExpr{Float64,VariableRef}

cf = Matrix{JuMP.QuadExpr}(undef, 2time_lapses, number_of_players)
for i in 1:2time_lapses
for j in 1:number_of_players
cf[i, j] = zero(JuMP.QuadExpr)
end
end
for i in 1:number_of_prosumers
for j in 1:(time_lapses*2)
JuMP.add_to_expression(cf[j,i], u[j,i], u[j,i])
end
end

but in JuMP master, you should be able to do

cf = @expression(m, [1:(time_lapses*2),1:number_of_players],
sum(u[j,i]*u[j,i] for i in 1:number_of_prosumers, j in 1:(time_lapses*2)))