# Three state variable

**URL:** <https://discourse.julialang.org/t/three-state-variable/53632>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [January 19, 2021, 7:07pm UTC](https://discourse.julialang.org/t/three-state-variable/53632 "2021-01-19T19:07:17Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [January 19, 2021, 11:17pm UTC](https://discourse.julialang.org/t/three-state-variable/53632/6 "2021-01-19T23:17:01Z")

</div>

Take a read of [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).

In particular, take the time to make a minimal working example (i.e., code that we can copy-and-paste) that demonstrates what you are trying to achieve and why.

If `vector1` and `vector2` are vectors, but `x1` and `x2` are scalars, the result is a vector, so computing the `sign` doesn’t make sense.

If your model is linear, you can use a MILP reformulation:

```nohighlight
model = Model()
L, U = -100, 100
@variable(model, L <= x <= U)
@variable(model, y, Bin)
@constraint(model, x <= U * y)
@constraint(model, x >= L * (1 - y))
@expression(model, sgn, 2 * y - 1)

```

If your model is nonlinear, you may be better off with a smooth approximation:  
[https://math.stackexchange.com/questions/1264681/how-to-smoothly-approximate-a-sign-function](https://math.stackexchange.com/questions/1264681/how-to-smoothly-approximate-a-sign-function)

---

_[View the full topic](https://discourse.julialang.org/t/three-state-variable/53632)._
