JuMP nonlinear optimization error: unrecogniced function

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
@NLobjective(m, Min, f(x))
status = solve(m)
println("Objective value: ", getobjectivevalue(m))

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

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

before @NLobjective.

1 Like