# Comparison involving variables with JuMP

**URL:** https://discourse.julialang.org/t/comparison-involving-variables-with-jump/4551
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [June 29, 2017, 8:04pm UTC](https://discourse.julialang.org/t/comparison-involving-variables-with-jump/4551 "2017-06-29T20:04:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kguo](https://avatars.discourse-cdn.com/v4/letter/k/67e7ee/32.png) [@kguo](https://discourse.julialang.org/u/kguo)
#### Post date: [June 29, 2017, 8:04pm UTC](https://discourse.julialang.org/t/comparison-involving-variables-with-jump/4551/1 "2017-06-29T20:04:02Z")

</div>

I am new to Julia/JuMP. Is it possible to perform comparison on variable. For example, is there something close to the following?

maximum(M[1,:]. \* myFunction(x))

M is a nxn matrix and x is a variable.

If not, what’s the best way to deal with this kind of issues?

I’d really appreciate any suggestions.

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [June 29, 2017, 8:09pm UTC](https://discourse.julialang.org/t/comparison-involving-variables-with-jump/4551/2 "2017-06-29T20:09:15Z")

</div>

In an optimization problem, rather than writing `y = maximum(x)`, we typically would create a new slack variable called `y` and constrain that:

```julia
@constraint model y .>= x

```

That will work if there is something in your objective or other constraints which is pushing “down” on `y`. For example

```julia
@variable model x >= 0
(add some other constraints on x)
@variable model y
@constraint model y .>= x
@objective model Min y

```

If you can’t rely on your objective or other constraints to push down on the value of `y`, then you have a much harder problem. You could implement that as a mixed-integer optimization, but I wouldn’t go down that road right away.

---

<div class="post-metadata">

### Author: ![kguo](https://avatars.discourse-cdn.com/v4/letter/k/67e7ee/32.png) [@kguo](https://discourse.julialang.org/u/kguo)
#### Post date: [June 29, 2017, 8:29pm UTC](https://discourse.julialang.org/t/comparison-involving-variables-with-jump/4551/3 "2017-06-29T20:29:56Z")

</div>

Thanks for the quick response. Yes, the min max approach worked. I actually tried that before. It failed, but on something else which I just found out was a simple typo ☹
