# Help to correct this code please

**URL:** https://discourse.julialang.org/t/help-to-correct-this-code-please/78421
**Category:** New to Julia
**Created:** [March 24, 2022, 5:34pm UTC](https://discourse.julialang.org/t/help-to-correct-this-code-please/78421 "2022-03-24T17:34:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Eric.O](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@Eric.O](https://discourse.julialang.org/u/Eric.O)
#### Post date: [March 24, 2022, 5:34pm UTC](https://discourse.julialang.org/t/help-to-correct-this-code-please/78421/1 "2022-03-24T17:34:00Z")

</div>

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]  
NumVar=5  
#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)

##Constraints

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())

end

@show model  
print(model)  
optimize!(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]))  
end

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [March 24, 2022, 7:26pm UTC](https://discourse.julialang.org/t/help-to-correct-this-code-please/78421/2 "2022-03-24T19:26:39Z")

</div>

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

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 24, 2022, 7:29pm UTC](https://discourse.julialang.org/t/help-to-correct-this-code-please/78421/3 "2022-03-24T19:29:33Z")

</div>

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.
