# MethodError: no method matching in JuMP

**URL:** <https://discourse.julialang.org/t/methoderror-no-method-matching-in-jump/66543>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [August 17, 2021, 11:50am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-in-jump/66543 "2021-08-17T11:50:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangsanle](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@zhangsanle](https://discourse.julialang.org/u/zhangsanle)\
**Post date:** [August 17, 2021, 11:50am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-in-jump/66543/1 "2021-08-17T11:50:06Z")

</div>

I am new in julia. When i use JuMP, i meet some problems: MethodError: no method matching (::Interpolations.Extrapolation{Float64, 1, ScaledInterpolation{Float64, 1, Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}}}, BSpline{Linear{Throw{OnGrid}}}, Throw{Nothing}})(::AffExpr)  
Use square brackets for indexing an Array.  
Closest candidates are:  
(::Interpolations.Extrapolation{T, N, ITPT, IT, ET} where {ITPT, IT, ET})(::Number…) where {T, N} at

```julia
using JuMP
import Ipopt
β = 0.88
Nb = 1000
δ = 1.5
wage = 1
rate = 1
grid_b = range(0, 5, length = 1000)
w = 5 * (grid_b).^2
w_func = LinearInterpolation(grid_b, w)
choice1 = Model(Ipopt.Optimizer)  
@variable(choice1, x >= 0)
@NLobjective(choice1, Max, x^δ/(1-δ) + β * (w_func.((grid_b[3]*(1+rate)+wage-x) * 3))) 
optimize!(choice1)  

```

---

<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:** [August 17, 2021, 8:09pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-in-jump/66543/2 "2021-08-17T20:09:34Z")

</div>

You can’t use arbitrary functions in JuMP. You need to use a user-defined function:  
[https://jump.dev/JuMP.jl/stable/manual/nlp/#User-defined-Functions](https://jump.dev/JuMP.jl/stable/manual/nlp/#User-defined-Functions)

But this will only work if it’s possible to automatically differentiate the function. I don’t know if that works with Interpolations.jl.
