Bounderror during interpolation

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"
}

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> 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.
1 Like

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

1 Like