# Unstable quadratic spline from DataInterpolations.jl

**URL:** <https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435>\
**Category:** Numerics\
**Tags:** sciml, datainterpolations\
**Created:** [November 9, 2024, 12:07am UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435 "2024-11-09T00:07:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [November 9, 2024, 12:07am UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435/1 "2024-11-09T00:07:54Z")

</div>

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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/4/34357d199a4520b699ee83861e28debff5fdb0c4.png)

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.

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

# Interpolated values
y_new = quadratic_spline(x_new)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/6/868a66abe2b5aa4ae9fafccc779e69539b5ea032.png)

Any idea for this strange behaviour?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 9, 2024, 5:04am UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435/2 "2024-11-09T05:04:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [November 9, 2024, 3:19pm UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435/3 "2024-11-09T15:19:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [November 9, 2024, 4:29pm UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435/4 "2024-11-09T16:29:41Z")

</div>

Here is the MWE

> **MWE**
>
> ```julia
> 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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/7/c70653657a118f376515c661bba095e51dd7a90c.png)

---

<div class="post-metadata">

**Author:** ![marcobonici](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcobonici/32/20549_2.png) [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Post date:** [November 9, 2024, 4:37pm UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435/5 "2024-11-09T16:37:32Z")

</div>

@ChrisRackauckas I opened an [issue](https://github.com/SciML/DataInterpolations.jl/issues/353) as requested. I posted everything as requested there.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 9, 2024, 4:43pm UTC](https://discourse.julialang.org/t/unstable-quadratic-spline-from-datainterpolations-jl/122435/6 "2024-11-09T16:43:45Z")

</div>

Thanks!
