JuMP nonlinear optimization error: unrecogniced function

jump

#1

What does the following error mean when trying to optimize a nonlinear objective function f:

ERROR: LoadError: Unrecognized function "f" used in nonlinear expression.

This is how I tried to use the nonlinear features of JuMP:

using JuMP, NLopt
m = Model(solver = NLoptSolver(algorithm=:LD_SLSQP))
@variable(m, x[1:30])
for i in 1:30
    setvalue(x[i],x0[i])
end
@NLobjective(m, Min, f(x))
status = solve(m)
println("Objective value: ", getobjectivevalue(m))

#2

You need to register your function f by doing, e.g.,

JuMP.register(m, :f, 1, f, autodiff=true)

before @NLobjective.