# NLconstraint: equality, absolute value

**URL:** <https://discourse.julialang.org/t/nlconstraint-equality-absolute-value/18674>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [December 14, 2018, 11:09pm UTC](https://discourse.julialang.org/t/nlconstraint-equality-absolute-value/18674 "2018-12-14T23:09:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [December 14, 2018, 11:09pm UTC](https://discourse.julialang.org/t/nlconstraint-equality-absolute-value/18674/1 "2018-12-14T23:09:08Z")

</div>

I have a nonlinear, nonconvex equality constraint, and I only care about its magnitude. I saw this [thread](https://github.com/JuliaOpt/JuMP.jl/issues/48) but wasn’t sure how to best handle the constraint in the nonconvex case. For example, I want something like:

```julia
m = Model(solver=IpoptSolver())
@variable(m, -pi/2 <= x <= pi/2)
@objective(m, Min, x)
@NLconstraint(m, absval_constraint, abs(sin(x)) == 0.5)

```

I tried adding constraints like:

```julia
@NLconstraint(m, c1, sin(x) <= 0.5)
@NLconstraint(m, c2, sin(x) >= -0.5)
@NLconstraint(m, c3, sin(x) >= 0.5)
@NLconstraint(m, c4, sin(x) <= -0.5)

```

but it makes sense that when solving, it’s infeasible unless I start from `x = -pi/6` or `x = pi/6`.

I only have one constraint like this, so I could solve the problem twice separately with equality constraints (1) `sin(x) == 0.5` and (2) `sin(x) == -0.5`, but is this what’s typically done? Is there a better way?

---

<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:** [December 17, 2018, 12:13am UTC](https://discourse.julialang.org/t/nlconstraint-equality-absolute-value/18674/2 "2018-12-17T00:13:50Z")

</div>

The issue you linked to is more for linear problems. When I tried, Ipopt found the correct answer for your original problem. What’s the issue?

Also, I don’t think your constraints are doing that you think they’re doing. In particular, `c3` and `c4` make the problem infeasible regardless of `x`.
