# Evaluate a nonlinear expression at a point

**URL:** <https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279>\
**Category:** Optimization (Mathematical)\
**Created:** [December 5, 2022, 9:00pm UTC](https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279 "2022-12-05T21:00:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Post date:** [December 5, 2022, 9:00pm UTC](https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279/1 "2022-12-05T21:00:24Z")

</div>

I have a model with many nonlinear expressions and I would like to evaluate these to test my model.

For example I have something like this

```julia
using JuMP
m = Model()

@variable(m,x)

@NLexpression(m,T,x^2)

#What is T(x=2)?

```

I’m writing an MCP model using the Complementarity package and a really useful model debugging technique is to evaluate the equations (NLexpressions in this case) at a solution point.

Any advice would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [December 5, 2022, 9:13pm UTC](https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279/2 "2022-12-05T21:13:44Z")

</div>

> [@Mitch\_Phillipson](#):
>
> ```julia
> using JuMP
> m = Model()
> 
> @variable(m,x)
> 
> @NLexpression(m,T,x^2)
> 
> #What is T(x=2)?
> 
> ```

Continue with:

```julia
value(v -> Dict(x => 2.0)[v], T)

```

The first argument takes a JuMP variable name, and returns a value. So essentially the `Dict` can contain several variables and other ways are legit, as long as they return a value.

---

<div class="post-metadata">

**Author:** ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Post date:** [December 5, 2022, 9:16pm UTC](https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279/3 "2022-12-05T21:16:53Z")

</div>

I had the arguments in the value backwards.

Thank you so much.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [December 5, 2022, 9:36pm UTC](https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279/4 "2022-12-05T21:36:08Z")

</div>

Actually, you are right, they are flipped. Had to jump to source to figure this out.

---

<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 5, 2022, 10:04pm UTC](https://discourse.julialang.org/t/evaluate-a-nonlinear-expression-at-a-point/91279/5 "2022-12-05T22:04:22Z")

</div>

We try to follow the Julia style guide: [Style Guide · The Julia Language](https://docs.julialang.org/en/v1/manual/style-guide/#Write-functions-with-argument-ordering-similar-to-Julia-Base)

It suggests that functions should always come as the first argument. The main reason is to allow the `do` syntax like:

```julia
value(T) do v
    return v == x ? 2.0 : 0.0
end

```
