# JuMP vector input in Nonlinear expressions

**URL:** <https://discourse.julialang.org/t/jump-vector-input-in-nonlinear-expressions/10361>\
**Category:** New to Julia\
**Tags:** jump, optimization\
**Created:** [April 16, 2018, 12:33pm UTC](https://discourse.julialang.org/t/jump-vector-input-in-nonlinear-expressions/10361 "2018-04-16T12:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [April 16, 2018, 12:33pm UTC](https://discourse.julialang.org/t/jump-vector-input-in-nonlinear-expressions/10361/1 "2018-04-16T12:33:29Z")

</div>

```julia
foo = x -> x[1]^2+x[1]*x[2]
m = Model(solver=IpoptSolver())
@variable(m,a[1:2])
JuMP.register(m, :f, 1, foo, autodiff=true)
@NLobjective(m,Min,f(a))

```

throws an error stating that nonlinear expressions may only contain scalar expressions.

```julia
foo2 = (x1,x2) -> x1^2+x1*x2
JuMP.register(m, :f2, 2, foo2, autodiff=true)
@NLobjective(m,Min,f2(a...))

```

Shouldn’t that be working with the “…”-expression? Or how to handle otherwise array inputs (in my case the size of the variable ‘a’ is changing)?

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [April 16, 2018, 12:34pm UTC](https://discourse.julialang.org/t/jump-vector-input-in-nonlinear-expressions/10361/2 "2018-04-16T12:34:44Z")

</div>

I am aware that

```julia
@NLobjective(m,Min,f2(a[1],a[2]))

```

is working.

---

<div class="post-metadata">

**Author:** ![ferrolho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ferrolho/32/213665_2.png) [@ferrolho](https://discourse.julialang.org/u/ferrolho)\
**Post date:** [March 19, 2019, 10:48pm UTC](https://discourse.julialang.org/t/jump-vector-input-in-nonlinear-expressions/10361/3 "2019-03-19T22:48:55Z")

</div>

You also need the splatting operator in the argument of `foo2`:

```julia
function foo2(x...)
    x[1]^2 + x[1]*x[2]
end

m = Model(solver=IpoptSolver())

@variable(m,a[1:2])

JuMP.register(m, :f2, 2, foo2, autodiff=true)
@NLobjective(m,Min,f2(a...))

```
