# Interpolate: BoundsError thrown in the interior

**URL:** <https://discourse.julialang.org/t/interpolate-boundserror-thrown-in-the-interior/17252>\
**Category:** General Usage\
**Created:** [November 7, 2018, 12:43pm UTC](https://discourse.julialang.org/t/interpolate-boundserror-thrown-in-the-interior/17252 "2018-11-07T12:43:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![axelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axelle/32/4488_2.png) [@axelle](https://discourse.julialang.org/u/axelle)\
**Post date:** [November 7, 2018, 12:43pm UTC](https://discourse.julialang.org/t/interpolate-boundserror-thrown-in-the-interior/17252/1 "2018-11-07T12:43:23Z")

</div>

Hi,  
I am using version 1.0.0.  
When using Interpolations, I am thrown a BoundsError for an evaluation inside the domain of the grid. I saw there were some already opened issues such as [#244](https://github.com/JuliaMath/Interpolations.jl/issues/244)) [#245](https://github.com/JuliaMath/Interpolations.jl/pull/245) but I could not see the solution error. I would be very grateful if someone could help me. It works for some interior values `(0.2)` or `(0.6898956231658479641)` but not for some others `(0.09697441557910233)` as you can see below - with no clear pattern for me.  
Many thanks!

`using Interpolations D_row = ([0.1, 1.05, 2.0],) Sb= [0.006167227715362695, 0.03223397506618452, 0.052729713214987387] Sb_func = interpolate(D_row, Sb, Gridded(Linear())) Sb_func(0.09697441557910233)`  
`  
BoundsError: attempt to access 3-element interpolate((::Array{Float64,1},), ::Array{Float64,1}, Gridded(Linear())) with element type Float64 at index [0.09697441557910233]

Stacktrace:  
[1] throw\_boundserror(::Interpolations.GriddedInterpolation{Float64,1,Float64,Gridded{Linear},Tuple{Array{Float64,1}}}, ::Tuple{Float64}) at .\abstractarray.jl:484  
[2] (::Interpolations.GriddedInterpolation{Float64,1,Float64,Gridded{Linear},Tuple{Array{Float64,1}}})(::Float64) at C:\Users\arquie.julia\packages\Interpolations\gioj0\src\gridded\indexing.jl:3  
[3] top-level scope at In[8]:5

Wherease` Sb_func(0.2)` or ` Sb_func(0.6898956231658479641)` works perfectly.

---

<div class="post-metadata">

**Author:** ![ksmcreynolds](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ksmcreynolds/32/860_2.png) [@ksmcreynolds](https://discourse.julialang.org/u/ksmcreynolds)\
**Post date:** [November 7, 2018, 2:17pm UTC](https://discourse.julialang.org/t/interpolate-boundserror-thrown-in-the-interior/17252/2 "2018-11-07T14:17:41Z")

</div>

The `BoundsError` occurs because you are trying to interpolate outside the domain. In your example, the domain is taken from `D_row` so `Sb_func(x)` can be evaluated for `0.1 <= x <= 2.0`. Since `0.09697441557910233 < 0.1` you get a `BoundsError`.

If you want to extrapolate, you can do that with `Sb_ext = extrapolate(Sb_fun, Flat())` for example. See the [Interpolations.jl README](https://github.com/JuliaMath/Interpolations.jl#extrapolation) for more info.

---

<div class="post-metadata">

**Author:** ![axelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axelle/32/4488_2.png) [@axelle](https://discourse.julialang.org/u/axelle)\
**Post date:** [November 7, 2018, 7:42pm UTC](https://discourse.julialang.org/t/interpolate-boundserror-thrown-in-the-interior/17252/3 "2018-11-07T19:42:45Z")

</div>

Thanks a lot. You are right, it was indeed outside of the domain, sorry about that. And thanks for the extrapolate syntax.
