Help to correct this code please

I want to write the code below in Julia but I keep getting the error
MethodError: no method matching getindex(::VariableRef, ::Int64)

Any help will be appreciated please. Thank you for your help.

using JuMP
using Mosek
using MosekTools
model= Model(Mosek.Optimizer)

#Input parameter
xs = [0, 5, -5, 4, -5]
ys = [0, 0.6, 0.5, -5, -4.5]
r=[0 0 0 0 0]
#Input varaibles
@variable(model, p[i=1:NumVar]>=0)
@variable(model, q[i=1:NumVar]>=0)
@variable(model, z[i=1:NumVar]>=0)
@variable(model, R>=0)
@variable(model, X>=0)
@variable(model, y>=0)

#Objective function
@objective(model, Min, R)


for i in 1:NumVar
@constraint(model, p[i] == X-xs[i])
@constraint(model, q[i] == y-ys[i])
@constraint(model, z[i] == R-r[i])
@constraint(model, [z[i], x[i], y[i]] in SecondOrderCone())


@show model
@show termination_status(model)
@show primal_status(model)
@show dual_status(model)
@show objective_value(model)
for i in 1:NumVar
println("x[$i] = ", value(x[i]))
println("y[$i] = ", value(y[i]))
println("z[$i] = ", value(z[i]))

what are x[i] and y[i] ? It looks to me, without running it, like they haven’t been defined

also, your code is not formatted and you haven’t included the full stacktrace

1 Like

To add to @lawless-m comments: AFAIK Mosek requires a commercial license. It would broaden your audience if you could provide a solver independent example.

1 Like