# JuMP + Alpine: Handling scalar functions with vector input using @NLexpression

**URL:** <https://discourse.julialang.org/t/jump-alpine-handling-scalar-functions-with-vector-input-using-nlexpression/111019>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [March 1, 2024, 2:45pm UTC](https://discourse.julialang.org/t/jump-alpine-handling-scalar-functions-with-vector-input-using-nlexpression/111019 "2024-03-01T14:45:46Z")\
**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:** [March 1, 2024, 8:58pm UTC](https://discourse.julialang.org/t/jump-alpine-handling-scalar-functions-with-vector-input-using-nlexpression/111019/2 "2024-03-01T20:58:58Z")

</div>

Hi @smallpondtom, welcome to the forum!

> I expect this to work for `@NLexpression`

It does not work, which is why I rewrote JuMP’s nonlinear support last year 😄 See [ANN: JuMP v1.15 is released](https://discourse.julialang.org/t/ann-jump-v1-15-is-released/103875) for details.

The answer of what to do depends greatly on what `V` and `V_dot` are.

I would use [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/dev/manual/nonlinear/#Function-tracing) and write your model as:

```Julia
using JuMP, Ipopt, LinearAlgebra

function LEDOA(V::Function, V_dot::Function, N::Int)
    model = Model(Ipopt.Optimizer)
    @variable(model, x[1:N])
    @variable(model, c >= 1e-8)
    @objective(model, Min, c)
    @constraint(model, V(x) - c == 0)
    @constraint(model, V_dot(x) == 0)
    optimize!(model)
    @assert is_solved_and_feasible(model)
    return value(c), value.(x)
end

A = [-2.0 0.0; 0.0 -1.0]
H = [0.0 0.5 0.5 0.0; 0.0 0.5 0.5 0.0]
P = [0.02078 0; 0 0.01292]
V(x) = x' * P * x
V_dot(x) = x' * P * A * x + x' * P * H * kron(x, x)
c, x = LEDOA(V, V_dot, 2)

```

---

_[View the full topic](https://discourse.julialang.org/t/jump-alpine-handling-scalar-functions-with-vector-input-using-nlexpression/111019)._
