# Modelling arbitrary non-linear expression (returned by a function) in JuMP

**URL:** <https://discourse.julialang.org/t/modelling-arbitrary-non-linear-expression-returned-by-a-function-in-jump/99419>\
**Category:** Optimization (Mathematical)\
**Created:** [May 26, 2023, 1:56am UTC](https://discourse.julialang.org/t/modelling-arbitrary-non-linear-expression-returned-by-a-function-in-jump/99419 "2023-05-26T01:56:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 26, 2023, 2:13am UTC](https://discourse.julialang.org/t/modelling-arbitrary-non-linear-expression-returned-by-a-function-in-jump/99419/2 "2023-05-26T02:13:12Z")

</div>

Unfortunately, you cannot do this very easily.

You can register a function which returns a scalar: [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nlp/#Register-a-function)

There is also a hack for user-defined functions which return a vector:

> **[Tips and tricks · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/tips_and_tricks/#User-defined-functions-with-vector-outputs)**
>
> Documentation for JuMP.

Longer-term, we’re in the middle of a rewrite to JuMP’s nonlinear interface, [https://github.com/jump-dev/JuMP.jl/pull/3106](https://github.com/jump-dev/JuMP.jl/pull/3106), which will make this work with no hacks or registered functions.

(p.s. I was having a conversation with @ccoffrin a few hours ago that this is _the_ most common question I get about JuMP. It comes up a few times every week… So hopefully we’ll have a better answer once that PR is merged.)

---

_[View the full topic](https://discourse.julialang.org/t/modelling-arbitrary-non-linear-expression-returned-by-a-function-in-jump/99419)._
