# Registering an array of functions and using them in constraints and objectives

**URL:** <https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [January 13, 2021, 5:39pm UTC](https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294 "2021-01-13T17:39:58Z")\
**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:** [January 18, 2021, 3:50am UTC](https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294/2 "2021-01-18T03:50:15Z")

</div>

This may help:

```nohighlight
using JuMP, Ipopt

function main(functions)
    model = Model(Ipopt.Optimizer)
    @variable(model, x)
    for (i, f) in enumerate(functions)
        f_sym = Symbol("f_$(i)")
        register(model, f_sym, 1, f; autodiff = true)
        add_NL_constraint(model, :($(f_sym)($x) <= 1.0))
    end
    return model
end

main([
    x -> x^2,
    x -> sin(x)^2,
])

```

I should add it as an example to the documentation. The current section on this is a little bare: [https://jump.dev/JuMP.jl/stable/nlp/#Raw-expression-input-1](https://jump.dev/JuMP.jl/stable/nlp/#Raw-expression-input-1)

---

_[View the full topic](https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294)._
