# UndefVarError: @variable not defined

**URL:** <https://discourse.julialang.org/t/undefvarerror-variable-not-defined/17903>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [November 23, 2018, 1:50pm UTC](https://discourse.julialang.org/t/undefvarerror-variable-not-defined/17903 "2018-11-23T13:50:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)\
**Post date:** [November 23, 2018, 1:50pm UTC](https://discourse.julialang.org/t/undefvarerror-variable-not-defined/17903/1 "2018-11-23T13:50:43Z")

</div>

hi Guys,  
recently i have been trying to write a code but when i run it it shows me this:  
“UndefVarError: @variable not defined” this is the entire code:  
’ ’ ’ Julia  
function scan\_maker(A)  
m = Model(solver=ClpSolver(PrimalTolerance=1e-3, DualTolerance=1e-3, InfeasibleReturn=1, PresolveType=1))  
# m = Model(solver=GurobiSolver())  
level = size(A, 2)  
v = zeros(Int, level)  
ub = zeros(Int, level)  
lb = zeros(Int, level)

```
@variable(m, x[1:level])
@constraint(m, con, A*x.>=0)

function setc(c)
    for i = 1:size(A, 1)
        m.linconstr[i].lb = float(c[i])
    end
end

function scan()
    i = 1
    init = 1
    while i > 0
        if i >= init
            @objective(m, Max, x[i])
            res = JuMP.solve(m, suppress_warnings=true)
            if res==:Optimal || res==:Unbounded
                ub[i] = round(Int, getvalue(x[i]))
                setobjectivesense(m, :Min)
                res = JuMP.solve(m, suppress_warnings=true)
                @assert res==:Optimal || res==:Unbounded
                lb[i] = round(Int, getvalue(x[i]))

                v[i] = lb[i]
                init += 1
            else
                @assert res==:Infeasible
                i -= 1
                continue
            end
        elseif v[i] < ub[i]
            v[i] += 1
        else
            setupperbound(x[i], Inf)
            setlowerbound(x[i], -Inf)
            init -= 1
            i -= 1
            continue
        end

        if i >= level
            produce(v)
            continue
        else
            setupperbound(x[i], v[i])
            setlowerbound(x[i], v[i])
            i += 1
        end
    end
end

return setc, scan

```

end  
’ ’ ’  
i don’t know if there is a missing Pakage or something.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [November 24, 2018, 9:02am UTC](https://discourse.julialang.org/t/undefvarerror-variable-not-defined/17903/2 "2018-11-24T09:02:51Z")

</div>

You probably need `using JuMP`.

---

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)\
**Post date:** [November 27, 2018, 6:57am UTC](https://discourse.julialang.org/t/undefvarerror-variable-not-defined/17903/3 "2018-11-27T06:57:18Z")

</div>

Thank you it worked.  
there are a lot of packages to be known in this language.
