Interpolations.jl icon indicating copy to clipboard operation
Interpolations.jl copied to clipboard

Inconsistent behavior in LinearInterpolation() vs CubicSplineInterpolation()

Open eirikbrandsaas opened this issue 5 years ago • 1 comments

Hi, as a part of a bigger project I was using linear interpolation and extrapolation. Now I want to experiment with different interpolations methods to check if my results are sensitive to that choice. I simply changed every instance of LinearInterpolation to CubicSplineInterpolation and hoped for the best, but I came across this slight inconsistency:

The error seems to be that the recipe for CubicSplineInterpolation does not accept the same type of grids as LinearInterpolation, as the following MWE illustrates:

## Setup
inigrid = 2:0.1:5
f(x,y) = log(x+y)
xs = zeros(31)
xs .= inigrid
ys = xs
A = [f(x,y) for x in xs, y in ys]

# Note that xs,ys are now vectors of length 31
## Linear works great
interp_linear = LinearInterpolation((xs, ys), A,extrapolation_bc = Line())
## Cubic Doesnt
interp_cubic = CubicSplineInterpolation((xs, ys), A,extrapolation_bc = Line())

Now, lets use the StepRange things instead of vectors, and it all works

## But if we always use the StepRange grids, it's all good...:
## Setup
inigrid = 2:0.1:5
xs = inigrid
ys = xs
A = [f(x,y) for x in xs, y in ys]

# Note that xs,ys are now Julias step-range things
## Linear works great
interp_linear = LinearInterpolation((xs, ys), A,extrapolation_bc = Line())
## Cubic DOES WORK!
interp_cubic = CubicSplineInterpolation((xs, ys), A,extrapolation_bc = Line())
##

eirikbrandsaas avatar Apr 13 '19 00:04 eirikbrandsaas

Arrays, rather than ranges, imply non-uniform interpolation. This is supported up to Linear order, but not up to Cubic order. A PR to fix that would be welcome!

timholy avatar May 08 '19 10:05 timholy