# Error with Ipopt 

**URL:** <https://discourse.julialang.org/t/error-with-ipopt/20989>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package\
**Created:** [February 19, 2019, 7:46pm UTC](https://discourse.julialang.org/t/error-with-ipopt/20989 "2019-02-19T19:46:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Y\_Li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/y_li/32/7573_2.png) [@Y\_Li](https://discourse.julialang.org/u/Y_Li)\
**Post date:** [February 19, 2019, 7:46pm UTC](https://discourse.julialang.org/t/error-with-ipopt/20989/1 "2019-02-19T19:46:04Z")

</div>

Hi, I am using JuMP and IPOPT to solve an non-linear optimization, below is my code

```julia
using JuMP
using Ipopt
model =Model(solver=IpoptSolver())
@variable(model, x )
@variable(model, y )
@variable(model, z )
#define our objective function
@NLobjective(model, Min,x/z)
#define our constraints
@constraint(model, x+y-1<=-0.01)
@NLconstraint(model, -x+y*z+1<=-0.01)
@constraint(model, -x<=-0.01)
@constraint(model, -y<=-0.01)
@constraint(model, -z<=-0.01)

print(model)
#solve statement
status = solve(model)
println("Objective value: ", getobjectivevalue(model))
println("x = ", getvalue(x))
println("y = ", getvalue(y))
println("z = ", getvalue(z))

```

And for some reasons it returns

```julia
EXIT: Invalid number in NLP function or derivative detected.
┌ Warning: Ipopt finished with status Invalid_Number_Detected
└ @ Ipopt ~/.julia/packages/Ipopt/Iu7vT/src/MPB_wrapper.jl:178
┌ Warning: Not solved to optimality, status: Error
└ @ JuMP ~/.julia/packages/JuMP/PbnIJ/src/nlp.jl:1283
Objective value: 0.0
x = 0.0
y = 0.0
z = 0.0

```

I can’t find any error in the code. Isn’t ipopt supposed to solve non-linear constraint optimization?

---

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [February 19, 2019, 7:59pm UTC](https://discourse.julialang.org/t/error-with-ipopt/20989/2 "2019-02-19T19:59:34Z")

</div>

It looks like ‘dividing by zero’ problem. In your objective function, you may add a small constant to the denominator, for example:

```julia
@NLobjective(model, Min, x / (z + 1e-9) )

```

Ipopt still didn’t give an optimal solution though. I think you need to consider reformulating the problem.

---

<div class="post-metadata">

**Author:** ![Y\_Li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/y_li/32/7573_2.png) [@Y\_Li](https://discourse.julialang.org/u/Y_Li)\
**Post date:** [February 20, 2019, 1:32am UTC](https://discourse.julialang.org/t/error-with-ipopt/20989/3 "2019-02-20T01:32:35Z")

</div>

Thanks!
