# How to use define interpolations in JuMP

**URL:** https://discourse.julialang.org/t/how-to-use-define-interpolations-in-jump/114126
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [May 10, 2024, 10:15pm UTC](https://discourse.julialang.org/t/how-to-use-define-interpolations-in-jump/114126 "2024-05-10T22:15:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Longblackcoffee](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Longblackcoffee](https://discourse.julialang.org/u/Longblackcoffee)
#### Post date: [May 10, 2024, 10:15pm UTC](https://discourse.julialang.org/t/how-to-use-define-interpolations-in-jump/114126/1 "2024-05-10T22:15:09Z")

</div>

Hi everyone,

Is there a way to register a user-defined function, generated from the Interpolations.jl package, into a JuMP model? Whenever I do, I get a method error. Here’s a MWE:

```julia
using JuMP, MadNLP
using Interpolations

x = LinRange(0, 1, 100); #Random input for interpolation
y = rand(100); #Random output for interpolation
func = LinearInterpolation(x, y, extrapolation_bc = Line()); #Function I want to register

model = Model(MadNLP.Optimizer; add_bridges = false)
JuMP.register(model, :func, 1, func, autodiff = true)

ERROR: MethodError: no method matching register(::Model, ::Symbol, ::Int64, ::Interpolations.Extrapolation{…}; autodiff::Bool)

```

Is there a workaround/alternative way to bypass this MethodError?

Cheers!

---

<div class="post-metadata">

### Author: ![marouane-f](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@marouane-f](https://discourse.julialang.org/u/marouane-f)
#### Post date: [May 10, 2024, 10:34pm UTC](https://discourse.julialang.org/t/how-to-use-define-interpolations-in-jump/114126/2 "2024-05-10T22:34:51Z")

</div>

I have never worked with these, but I tried doing the following as per the docs ([Register a function](https://jump.dev/JuMP.jl/stable/manual/nlp/#Register-a-function))

```julia
ffunc(x) = func(x); # define a function instead of an Interpolations.Extrapolation object

model = Model(MadNLP.Optimizer; add_bridges = false)

register(model, :func_name, 1, ffunc, autodiff = true)

```

and it seemed to work on my end

---

<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: [May 11, 2024, 12:19am UTC](https://discourse.julialang.org/t/how-to-use-define-interpolations-in-jump/114126/3 "2024-05-11T00:19:35Z")

</div>

@marouane-f is correct 😄 you must register a function, not an `Interpolations.Extrapolation` object.

Note that `JuMP.register` is for the legacy nonlinear interface. You should instead consider using the new `@operator` interface: [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nonlinear/#jump_user_defined_operators)
