JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
http://juliamath.github.io/Interpolations.jl/
Other
533 stars 109 forks source link

Nodes used when interpolating a node on grid #483

Open fredrikpaues opened 2 years ago

fredrikpaues commented 2 years ago

I have been frustrated by the code below returning NaN---presumably as the first two nodes ([Inf, 1.0]) are used to interpolate the queried value (2). Is there some way to change which nodes are used when querying a value on the grid?

using Interpolations
itp = LinearInterpolation([1, 2, 3], [Inf, 1.0, 0.5], extrapolation_bc=Line())
itp(2)
mkitti commented 2 years ago

Would this work?

julia> itp = LinearInterpolation([1, 2 - eps(2.0), 2, 3], [Inf, 1.0, 1.0, 0.5], extrapolation_bc=Line())
4-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Line()) with element type Float64:
  Inf
 NaN
   1.0
   0.5

julia> itp(2)
1.0
fredrikpaues commented 2 years ago

Good idea! That ought to work. Thanks!

eirikbrandsaas commented 2 years ago

Cross-referencing https://github.com/JuliaMath/Interpolations.jl/issues/459