# Convert Non-linear objective function from Maximization to Minimization

**URL:** <https://discourse.julialang.org/t/convert-non-linear-objective-function-from-maximization-to-minimization/84478>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, nonlinear\
**Created:** [July 19, 2022, 4:57pm UTC](https://discourse.julialang.org/t/convert-non-linear-objective-function-from-maximization-to-minimization/84478 "2022-07-19T16:57:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sophiepavia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sophiepavia/32/37488_2.png) [@sophiepavia](https://discourse.julialang.org/u/sophiepavia)\
**Post date:** [July 19, 2022, 4:57pm UTC](https://discourse.julialang.org/t/convert-non-linear-objective-function-from-maximization-to-minimization/84478/1 "2022-07-19T16:57:48Z")

</div>

Hello!

I have the following non linear objective function. How can I convert this maximization objective function to a minimization problem?

I have read conflicting material online, some say to multiple the problem by -1 others say to multiply by the reciprocal.  
Overall, I like the decision variable not to be in the denominator as well.

![Screenshot 2022-07-19 114929](https://global.discourse-cdn.com/julialang/original/3X/f/3/f3fae2738f9621e40eb81110c21ba492fd9899ac.png)  
Represented in Julia as

```julia
@NLobjective(model, Max, sum(b_dict[r] * (p_dict[r] * l_star[r] / l_[r]) for r in od))

```

where `b_dict[r]` , `p_dict[r]` and `l_star[r]` are lists of integers (representing demand, priority, and known arc length)

and `l_[r]` is a decision variable defined as `@variable(model,l_[od] >= 0) `

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 19, 2022, 6:27pm UTC](https://discourse.julialang.org/t/convert-non-linear-objective-function-from-maximization-to-minimization/84478/2 "2022-07-19T18:27:55Z")

</div>

The most usual practice is to multiply by -1. That has the advantage of not introducing complications that my lead to unexpected gradients/Hessian.

---

<div class="post-metadata">

**Author:** ![sophiepavia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sophiepavia/32/37488_2.png) [@sophiepavia](https://discourse.julialang.org/u/sophiepavia)\
**Post date:** [July 19, 2022, 6:47pm UTC](https://discourse.julialang.org/t/convert-non-linear-objective-function-from-maximization-to-minimization/84478/3 "2022-07-19T18:47:15Z")

</div>

Got it,

It is possible to multiply the reciprocal as well though, correct?

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 19, 2022, 8:31pm UTC](https://discourse.julialang.org/t/convert-non-linear-objective-function-from-maximization-to-minimization/84478/4 "2022-07-19T20:31:26Z")

</div>

Consider maximizing -x^2. The reciprocal is -1/x^2. This has no minimum, and the derivative at x=0 is undefined. For a problem like this, a gradient-based optimizer will encounter problems. On the other hand, if you just multiply by -1, you won’t have any trouble.
