# JuMP register polynomial with its gradient

**URL:** https://discourse.julialang.org/t/jump-register-polynomial-with-its-gradient/82876
**Category:** Optimization (Mathematical)
**Created:** [June 16, 2022, 2:07pm UTC](https://discourse.julialang.org/t/jump-register-polynomial-with-its-gradient/82876 "2022-06-16T14:07:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.julialang.org/u/Luca)
#### Post date: [June 16, 2022, 2:07pm UTC](https://discourse.julialang.org/t/jump-register-polynomial-with-its-gradient/82876/1 "2022-06-16T14:07:09Z")

</div>

Dear all,

I am using jump and I want to register a polynomial function with its gradient, with

`register(model2, :poly, num_var, poly, gradient)`

I build the polynomial with AbstractAlgebra.jl and the gradient with the function

```julia
function gradient(x...)
    point = Float64[]
    for i in 1:length(x)
        append!(point,x[i])
    end
    gradient = Float64[]
    for i in 1:length(x)
        deriv = evaluate(derivative(f,i),point)
        append!(gradient,convert(Float64,deriv))
    end
    return gradient
end

```

If I call the gradient on a point with

`gradient(zeros(100))`

there is no error. However, when I solve my problem with Ipopt as follows

```julia
num_var = 100
model = Model(Ipopt.Optimizer)
register(model, :poly, num_var, poly, gradient)
@variable(model, 0.0 <= z[1:num_var] <= 1.0)
@NLobjective(model, Min, poly(z...))
optimize!(model)

```

JuMP return me the following error message referring to the evaluation step in the gradient of the function.

`ERROR: LoadError: Incorrect number of values in evaluation`

I would ask you if you have any insight or suggestion to solve this error. Thanks very much

---

<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: [June 16, 2022, 6:39pm UTC](https://discourse.julialang.org/t/jump-register-polynomial-with-its-gradient/82876/2 "2022-06-16T18:39:55Z")

</div>

Your gradient function need to accept the gradient as the first argument and modify it in place.

[https://jump.dev/JuMP.jl/stable/manual/nlp/#Multivariate-functions](https://jump.dev/JuMP.jl/stable/manual/nlp/#Multivariate-functions)
