JuliaMath / JuliaMath/Interpolations.jl

Inconsistent behavior in LinearInterpolation() vs CubicSplineInterpolation()

Open
#312 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
575
Forks
117
PR merge metrics
No merged PRs in 30d

Description

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())
##
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.