SciML / DataInterpolations.jl

A library of data interpolation and smoothing functions
MIT License
203 stars 43 forks source link

fix: CubicSpline's natural boundary conditions #235

Closed sathvikbhagavan closed 3 months ago

sathvikbhagavan commented 3 months ago

Fixes: #234

Now we get the same outputs as scipy

julia> CubicS.(v)
20-element Vector{Float64}:
 318.6243760456969
 334.40200181048806
 347.13345942996295
 356.2838248343795
 362.79265929502935
 367.66363214151
 371.88318244762684
 376.04145340397156
 380.33229231792177
 384.9323162410631
 390.002925359128
 395.35553194322165
 400.451560349822
 404.7372180695537
 407.7255576184023
 410.46706709565404
 415.5496701838955
 425.6281355910744
 443.20840335017215
 467.3733539699478

image

https://en.wikiversity.org/wiki/Cubic_Spline_Interpolation

The first entry of the third column and last entry of first column in the tridiagonal matrix should have been zero.

For the tests, the polynomial mentioned in https://github.com/SciML/DataInterpolations.jl/blob/master/test/interpolation_tests.jl#L501 is not correct for natural boundary condition. Found the right ones in https://tools.timodenk.com/cubic-spline-interpolation

image