# Bounderror during interpolation

**URL:** <https://discourse.julialang.org/t/bounderror-during-interpolation/121340>\
**Category:** General Usage\
**Tags:** interpolations, error-message\
**Created:** [October 15, 2024, 5:20pm UTC](https://discourse.julialang.org/t/bounderror-during-interpolation/121340 "2024-10-15T17:20:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goodness](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@Goodness](https://discourse.julialang.org/u/Goodness)\
**Post date:** [October 15, 2024, 5:20pm UTC](https://discourse.julialang.org/t/bounderror-during-interpolation/121340/1 "2024-10-15T17:20:03Z")

</div>

Hello  
I want to run a simulation that requires iteration and interpolation, but I have been encountering this error, and the simulation will end after some iteration.

{  
“name”: “BoundsError”,  
“message”: “BoundsError: attempt to access 20×73×7 interpolate((::Vector{Float64},::Vector{Float64},::Vector{Float64}), ::Array{Float64, 3}, Gridded(Linear())) with element type Float64 at index [0.45414336821466633, 0.0, 0.6]”,  
“stack”: "BoundsError: attempt to access 20×73×7 interpolate((::Vector{Float64},::Vector{Float64},::Vector{Float64}), ::Array{Float64, 3}, Gridded(Linear())) with element type Float64 at index [0.45414336821466633, 0.0, 0.6]

Stacktrace:  
[1] throw\_boundserror(A::Interpolations.GriddedInterpolation{Float64, 3, Array{Float64, 3}, Gridded{Linear{Throw{OnGrid}}}, Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, I::Tuple{Float64, Float64, Float64})  
@ Base ./abstractarray.jl:737  
[2] GriddedInterpolation  
@ ~/.julia/packages/Interpolations/91PhN/src/gridded/indexing.jl:3 [inlined]  
[3] aero\_coeffs(sigma::Float64, lambda::Float64, mach::Float64, delta\_1::Int64, delta\_2::Int64, delta\_3::Int64, delta\_4::Int64, mrc::Float64, cg::Float64, s\_ref::Float64, l\_ref::Float64, CAB::Array{Float64, 3}, CNB::Array{Float64, 3}, CYB::Array{Float64, 3}, CLLB::Array{Float64, 3}, CLMB::Array{Float64, 3}, CLNB::Array{Float64, 3}, CNQ::Matrix{Float64}, CNAD::Matrix{Float64}, CYP::Array{Float64, 3}, CYR::Array{Float64, 3}, CLLP::Array{Float64, 3}, CLLR::Array{Float64, 3}, CLMAD::Matrix{Float64}, CLMQ::Matrix{Float64}, CLNP::Array{Float64, 3}, CLNR::Array{Float64, 3}, dCAd1::Array{Float64, 4}, dCAd2::Array{Float64, 4}, dCAd3::Array{Float64, 4}, dCAd4::Array{Float64, 4}, dCNd1::Array{Float64, 4}, dCNd2::Array{Float64, 4}, dCNd3::Array{Float64, 4}, dCNd4::Array{Float64, 4}, dCYd1::Array{Float64, 4}, dCYd2::Array{Float64, 4}, dCYd3::Array{Float64, 4}, dCYd4::Array{Float64, 4}, dCLLd1::Array{Float64, 4}, dCLLd2::Array{Float64, 4}, dCLLd3::Array{Float64, 4}, dCLLd4::Array{Float64, 4}, dCLMd1::Array{Float64, 4}, dCLMd2::Array{Float64, 4}, dCLMd3::Array{Float64, 4}, dCLMd4::Array{Float64, 4}, dCLNd1::Array{Float64, 4}, dCLNd2::Array{Float64, 4}, dCLNd3::Array{Float64, 4}, dCLNd4::Array{Float64, 4}, sigmat::Matrix{Float64}, lambdat::Matrix{Float64}, deltat::Matrix{Float64}, macht::Matrix{Float64})  
@ Main ~/Desktop/Drive\_Download/Reference\_simulation-Goodness/Reference\_simulation/aero\_coeffs.jl:79  
[4] Aerodynamics(constant::Constant, δ\_1234::Vector{Int64}, ρ::Float64, vs::Float64, mach::Float64, p::Float64, q::Float64, r::Float64, σ::Float64, λ::Float64, σ̇::Int64, sigmat::Matrix{Float64}, deltat::Matrix{Float64}, macht::Matrix{Float64}, CAB::Array{Float64, 3}, CNB::Array{Float64, 3}, CYB::Array{Float64, 3}, CLLB::Array{Float64, 3}, CLMB::Array{Float64, 3}, CLNB::Array{Float64, 3}, CNQ::Matrix{Float64}, CNAD::Matrix{Float64}, CYP::Array{Float64, 3}, CYR::Array{Float64, 3}, CLLP::Array{Float64, 3}, CLLR::Array{Float64, 3}, CLMAD::Matrix{Float64}, CLMQ::Matrix{Float64}, CLNP::Array{Float64, 3}, CLNR::Array{Float64, 3}, dCAd1::Array{Float64, 4}, dCAd2::Array{Float64, 4}, dCAd3::Array{Float64, 4}, dCAd4::Array{Float64, 4}, dCNd1::Array{Float64, 4}, dCNd2::Array{Float64, 4}, dCNd3::Array{Float64, 4}, dCNd4::Array{Float64, 4}, dCYd1::Array{Float64, 4}, dCYd2::Array{Float64, 4}, dCYd3::Array{Float64, 4}, dCYd4::Array{Float64, 4}, dCLLd1::Array{Float64, 4}, dCLLd2::Array{Float64, 4}, dCLLd3::Array{Float64, 4}, dCLLd4::Array{Float64, 4}, dCLMd1::Array{Float64, 4}, dCLMd2::Array{Float64, 4}, dCLMd3::Array{Float64, 4}, dCLMd4::Array{Float64, 4}, dCLNd1::Array{Float64, 4}, dCLNd2::Array{Float64, 4}, dCLNd3::Array{Float64, 4}, dCLNd4::Array{Float64, 4}, lambdat::Matrix{Float64})  
@ Main ~/Desktop/Drive\_Download/Reference\_simulation-Goodness/Reference\_simulation/jl\_notebook\_cell\_df34fa98e69747e1a8f8a730347b8e2f\_X25sZmlsZQ==.jl:34  
[5] EoM\_Goodness(state::Matrix{Float64}, inertial::Inertial, δ::delta, constant::Constant)  
@ Main ~/Desktop/Drive\_Download/Reference\_simulation-Goodness/Reference\_simulation/jl\_notebook\_cell\_df34fa98e69747e1a8f8a730347b8e2f\_X26sZmlsZQ==.jl:125  
[6] top-level scope  
@ ~/Desktop/Drive\_Download/Reference\_simulation-Goodness/Reference\_simulation/jl\_notebook\_cell\_df34fa98e69747e1a8f8a730347b8e2f\_X35sZmlsZQ==.jl:17"  
}

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [October 15, 2024, 6:28pm UTC](https://discourse.julialang.org/t/bounderror-during-interpolation/121340/2 "2024-10-15T18:28:50Z")

</div>

Hi, and welcome to the Julia community!

In general it would help if you could provide the relevant part of the code yielding this error, ideally condensed down to a minimal working example. In this case, the error just seems to be that you are requesting a value from outside of the interpolation region. E.g.

```julia-repl
julia> using Interpolations

julia> nodes = ([x for x = 1.:5.], [y^2 for y = 2.:7.], [z^3 for z = 3.:9.])
([1.0, 2.0, 3.0, 4.0, 5.0], [4.0, 9.0, 16.0, 25.0, 36.0, 49.0], [27.0, 64.0, 125.0, 216.0, 343.0, 512.0, 729.0])

julia> values = rand(length.(nodes)...); # size == (5, 6, 7)

julia> itp = interpolate(nodes, values, Gridded(Linear()));

julia> itp(2.5, 10., 40.) # works fine as we are within the node bounds (1. <= 2.5 <= 5. for the first coordinate, 4. <= 10. <= 49. for the second, 27. <= 40. <= 729. for the third)
0.37922761110738357

julia> itp(0., 10., 40.) # will throw a BoundsError as not 1. <= 0. <= 5. for the first coordinate
ERROR: BoundsError: attempt to access 5×6×7 interpolate((::Vector{Float64},::Vector{Float64},::Vector{Float64}), ::Array{Float64, 3}, Gridded(Linear())) with element type Float64 at index [0.0, 10.0, 40.0]
Stacktrace:
 [1] throw_boundserror(A::Interpolations.GriddedInterpolation{…}, I::Tuple{…})
   @ Base .\abstractarray.jl:737
 [2] (::Interpolations.GriddedInterpolation{Float64, 3, Array{…}, Gridded{…}, Tuple{…}})(::Float64, ::Float64, ::Float64)
   @ Interpolations (...)\.julia\packages\Interpolations\91PhN\src\gridded\indexing.jl:3
 [3] top-level scope
   @ REPL[102]:1
Some type information was truncated. Use `show(err)` to see complete types.
```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [October 16, 2024, 5:33am UTC](https://discourse.julialang.org/t/bounderror-during-interpolation/121340/3 "2024-10-16T05:33:14Z")

</div>

If you want to extrapolate rather than interpolate see. The docs here

> **[Extrapolation · Interpolations.jl](https://juliamath.github.io/Interpolations.jl/latest/extrapolation/#Extrapolation)**
>
> Documentation for Interpolations.jl.
