# Error message using JuMP and NLopt

**URL:** <https://discourse.julialang.org/t/error-message-using-jump-and-nlopt/3255>\
**Category:** General Usage\
**Created:** [April 17, 2017, 9:16pm UTC](https://discourse.julialang.org/t/error-message-using-jump-and-nlopt/3255 "2017-04-17T21:16:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jic](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jic](https://discourse.julialang.org/u/jic)\
**Post date:** [April 17, 2017, 9:16pm UTC](https://discourse.julialang.org/t/error-message-using-jump-and-nlopt/3255/1 "2017-04-17T21:16:01Z")

</div>

Dear Julia experts,

I have been using JuMP and NLopt for an optimization problem about a year ago and in trying to rerun the code which worked, I am getting an error message. I have three non-linear constraints (I am only showing one here) and I am trying to register my function(the actual function is not shown) using JuMP.register and find maximum of the function.  
Please see my code below along with the error message.

CODE :  
p = 10  
m1 = Model(solver=NLoptSolver(algorithm=:LN\_COBYLA))

#- define variables  
@variable(m1, a[i=1:p])  
@variable(m1, b[i=1:p])

function myf1(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10)  
##-- my own function --##  
end

JuMP.register(m1, :myf1, 2\*p, myf1)

@NLobjective(m1, Max, myf1(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10]))  
@constraint(m1, a’\*a .== 1)

ERROR MESSAGE :  
julia\> JuMP.register(m1, :myf1, 2\*p, myf1)  
ERROR: MethodError: `register` has no method matching register(::JuMP.Model, ::Symbol, ::Int64, ::Function)  
Closest candidates are:  
register(::Symbol, ::Integer, ::Function, ::Function)  
register(::Symbol, ::Integer, ::Function, ::Function, ::Function)

I tried to change the order to the candidates but cannot find the syntax that works.  
Can someone please help me to fix the error?  
Thank you.

---

<div class="post-metadata">

**Author:** ![evanfields](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evanfields/32/1744_2.png) [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Post date:** [April 17, 2017, 11:11pm UTC](https://discourse.julialang.org/t/error-message-using-jump-and-nlopt/3255/2 "2017-04-17T23:11:38Z")

</div>

What JuMP version are you using? On `0.16.2` I have a method matching that signature:

```julia
julia> methods(JuMP.register)
# 6 methods for generic function "register":
register(m::JuMP.Model, s::Symbol, dimension::Integer, f::Function; autodiff) at C:\Users\Evan\.julia\v0.5\JuMP\src\nlp.jl:1364

```

If I recall correctly, you also have to specify `autodiff = true` if you don’t provide a gradient function.

---

<div class="post-metadata">

**Author:** ![jic](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jic](https://discourse.julialang.org/u/jic)\
**Post date:** [April 18, 2017, 2:57am UTC](https://discourse.julialang.org/t/error-message-using-jump-and-nlopt/3255/3 "2017-04-18T02:57:36Z")

</div>

Thank you very much. I updated my JuMP package and the problem is solved.
