Unstable quadratic spline from DataInterpolations.jl

I have a problem when using the quadratic spline from DataInterpolations.jl.

I have some data (blue curve) I want to interpolate on a finer grid. I tried to use a quadratic (orange) and a cubic (green) spline.

DataInterpolations.QuadraticSpline(y, k).(new_k)

DataInterpolations.CubicSpline(y, k).(new_k)

When I plot

I can for sure just use the cubic spline and avoid being annoying…but why is this the result I get? I would have not expected that kind of behaviour.
Also, when feeding the same data to scipy, I get no issues.

# Interpolation using quadratic spline
quadratic_spline = interp1d(x, y, kind='quadratic')

# Interpolated values
y_new = quadratic_spline(x_new)

Any idea for this strange behaviour?

1 Like

That’s odd, open an issue that reproduces the behavior. You didn’t share any code here and this needs an MWE.

Sure, you are right.
I will share the code and the exact values of the u and t, so you can test everything, both here and on the issue.

Here is the MWE

MWE
using DataInterpolations
using Plots
x = [
    0.0010000000000000002,
    0.0017752321946474007,
    0.0024267002652361017,
    0.0033172416515725852,
    0.004534590584823373,
    0.006198677676141205,
    0.008473445223762798,
    0.011582998457310494,
    0.015833683905314526,
    0.021644269999465116,
    0.027500000000000004,
    0.035,
    0.045,
    0.05500000000000001,
    0.065,
    0.07500000000000001,
    0.08500000000000002,
    0.095,
    0.10500000000000001,
    0.11500000000000002,
    0.125,
    0.135,
    0.14500000000000002,
    0.15500000000000003,
    0.16500000000000004,
    0.17500000000000002,
    0.18500000000000003,
    0.19500000000000003,
    0.20500000000000004,
    0.21500000000000002,
    0.22500000000000003,
    0.23500000000000004,
    0.24500000000000002,
    0.255,
    0.265,
    0.275,
    0.28500000000000003,
    0.29500000000000004,
    0.30500000000000005,
    0.31500000000000006,
    0.32500000000000007,
    0.3350000000000001,
    0.3450000000000001,
    0.3550000000000001
]

y = [
    5190.637641981792,
    7054.516750766953,
    8483.359766937583,
    10242.377065660536,
    12311.64774616498,
    14597.662186600648,
    16874.673426455174,
    18741.458718393267,
    19601.555134229395,
    18791.388448976686,
    16849.721552634255,
    14119.969123708168,
    11401.438814333158,
    9872.291030242288,
    8897.45028292953,
    7939.589949465878,
    6921.696117540585,
    6045.454473119229,
    5442.664651823272,
    5065.775803272168,
    4790.269329831499,
    4525.179074496522,
    4254.760461650933,
    4009.1729908298153,
    3812.346818122069,
    3661.235920371446,
    3539.003374456872,
    3429.56319904424,
    3325.156402636274,
    3226.4245323568866,
    3138.3866304167577,
    3063.6389312516476,
    2999.2226261547366,
    2939.297113982252,
    2880.5669180920513,
    2824.330589926546,
    2772.657918361617,
    2726.2124622096726,
    2683.9727215170833,
    2644.1125465749265,
    2605.4010829283898,
    2568.214641677636,
    2532.46768215855,
    2498.262704089512
]
new_x = LinRange(x[1], x[end], 1000)
p = plot(x, y, label = "Data")
plot!(p, new_x, DataInterpolations.LinearInterpolation(y, x).(new_x), label = "Linear Interpolation")
plot!(p, new_x, DataInterpolations.QuadraticSpline(y, x).(new_x), label = "Quadratic Spline")
plot!(p, new_x, DataInterpolations.CubicSpline(y, x).(new_x), label = "Cubic Spline")
plot!(p, new_x, DataInterpolations.AkimaInterpolation(y, x).(new_x), label = "Akima Interpolation")
p

Which gives as output

@ChrisRackauckas I opened an issue as requested. I posted everything as requested there.

1 Like

Thanks!

1 Like