# Some trick in NLconstraint to avoid NaN or Inf for zero initial condition ?

**URL:** <https://discourse.julialang.org/t/some-trick-in-nlconstraint-to-avoid-nan-or-inf-for-zero-initial-condition/9831>\
**Category:** Optimization (Mathematical)\
**Created:** [March 20, 2018, 8:10am UTC](https://discourse.julialang.org/t/some-trick-in-nlconstraint-to-avoid-nan-or-inf-for-zero-initial-condition/9831 "2018-03-20T08:10:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfrodriguez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cfrodriguez/32/3768_2.png) [@cfrodriguez](https://discourse.julialang.org/u/cfrodriguez)\
**Post date:** [March 20, 2018, 8:10am UTC](https://discourse.julialang.org/t/some-trick-in-nlconstraint-to-avoid-nan-or-inf-for-zero-initial-condition/9831/1 "2018-03-20T08:10:51Z")

</div>

Hello all,

I am new using JuMP. In my code, I added a thermodynamic model (UNIQUAC). When xNT1 = 0.001 it work well. But when the value is almost zero (1e-11) it doesn’t work and JuMP give me “Warning: Cutting back alpha due to evaluation error”, “WARNING: Problem in step computation; switching to emergency mode.” and others warnings because of the term “ΨNT1/xNT1”.

```julia
@NLconstraint(m, log(gamNT1) == ((log(ΨNT1/xNT1) + (z/2.0)*q[1]*log(θNT1/ΨNT1) + lj[1] - (ΨNT1/xNT1)*(xNT1*lj[1]+xNT2*lj[2]+xNT3*lj[3]+xNT4*lj[4])) + (q[1]*(1.0-log(fNT1)-(dNT1))) ) )

```

I tried to use “ConditionalJuMP.jl” but I am using ipopt solver and it gives me that ipopt “Solver does not support discrete variables”  
So, there is some way to avoid that problem?  
In MATLAB I just use the if condition.  
If xNT1 == 0  
gamNT1 = 1  
else  
log(gamNT1) == ((log(ΨNT1/xNT1) +…,

---

<div class="post-metadata">

**Author:** ![cfrodriguez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cfrodriguez/32/3768_2.png) [@cfrodriguez](https://discourse.julialang.org/u/cfrodriguez)\
**Post date:** [March 21, 2018, 3:06am UTC](https://discourse.julialang.org/t/some-trick-in-nlconstraint-to-avoid-nan-or-inf-for-zero-initial-condition/9831/2 "2018-03-21T03:06:52Z")

</div>

Sorry, everyone,  
I solved the problem.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [February 26, 2019, 3:53am UTC](https://discourse.julialang.org/t/some-trick-in-nlconstraint-to-avoid-nan-or-inf-for-zero-initial-condition/9831/3 "2019-02-26T03:53:25Z")

</div>

Hi, how did you did it?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 26, 2019, 2:33pm UTC](https://discourse.julialang.org/t/some-trick-in-nlconstraint-to-avoid-nan-or-inf-for-zero-initial-condition/9831/4 "2019-02-26T14:33:57Z")

</div>

If you have `log(x)`, add a constraint that `x >= 0.001` (or some appropriate small positive value). You can also set the initial value of a variable using the `start` keyword:

`@variable(model, x >= 0.001, start = 1)`
