# Problem with Julia Ipopt

**URL:** <https://discourse.julialang.org/t/problem-with-julia-ipopt/3223>\
**Category:** Optimization (Mathematical)\
**Created:** [April 14, 2017, 6:34pm UTC](https://discourse.julialang.org/t/problem-with-julia-ipopt/3223 "2017-04-14T18:34:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Angshuman\_Goswami](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Angshuman\_Goswami](https://discourse.julialang.org/u/Angshuman_Goswami)\
**Post date:** [April 14, 2017, 6:34pm UTC](https://discourse.julialang.org/t/problem-with-julia-ipopt/3223/1 "2017-04-14T18:34:27Z")

</div>

I am trying to do vehicle control. I am trying to use the magic formula which is given by

@defNLExpr(mdl, FyR[i = 1:N] , D_sin(C_atan(B \* (atan((v\_y[i] - b\*r[i])/v\_x[i])))) )

Now when i run the code i am getting a error:

EXIT: Invalid number in NLP function or derivative detected.  
WARNING: Ipopt finished with status Invalid\_Number\_Detected

How do I get around this problem?

---

<div class="post-metadata">

**Author:** ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)\
**Post date:** [April 14, 2017, 7:23pm UTC](https://discourse.julialang.org/t/problem-with-julia-ipopt/3223/2 "2017-04-14T19:23:32Z")

</div>

Probably the division by `v_x`. If that was 0, then your function calculated an infinity or a nan and Ipopt gave you that error. Anything that appears in a denominator, you should make sure to initialize it to a nonzero starting point, and if possible, constrain it away from zero.

---

<div class="post-metadata">

**Author:** ![adowling2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adowling2/32/539_2.png) [@adowling2](https://discourse.julialang.org/u/adowling2)\
**Post date:** [April 18, 2017, 8:28pm UTC](https://discourse.julialang.org/t/problem-with-julia-ipopt/3223/3 "2017-04-18T20:28:23Z")

</div>

Try introducing an intermediate variable:

```julia
@variable(mdl, my_intr[i = 1:N]) # Add bounds if possible
@NLconstraint(mdl, calc_my_intr[i = 1:N], my_intr[i] * v_x[i] == v_y[i] - b*r[i])

```

This will avoid derivatives from exploding as v\_x[i] goes to 0.

Now for some shameless self-promotion. I recently shared a collection of JuMP model diagnostic tools on github. One feature includes finding NaNs in the Jacobian and printing out the offending constraint/variable.

[https://github.com/adowling2/DegeneracyHunter.jl](https://github.com/adowling2/DegeneracyHunter.jl)

---

<div class="post-metadata">

**Author:** ![Angshuman\_Goswami](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Angshuman\_Goswami](https://discourse.julialang.org/u/Angshuman_Goswami)\
**Post date:** [April 18, 2017, 9:28pm UTC](https://discourse.julialang.org/t/problem-with-julia-ipopt/3223/4 "2017-04-18T21:28:25Z")

</div>

Thanks for your help. I tried doing that but still it gives me the same error if I have anything in division.

---

<div class="post-metadata">

**Author:** ![Angshuman\_Goswami](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Angshuman\_Goswami](https://discourse.julialang.org/u/Angshuman_Goswami)\
**Post date:** [April 18, 2017, 9:29pm UTC](https://discourse.julialang.org/t/problem-with-julia-ipopt/3223/5 "2017-04-18T21:29:02Z")

</div>

Thanks I will try and get back to you asap
