Bug in cubic spline interpolator?
swharden opened this issue · 2 comments
@Marco-Sanguinetti recently commented the following on a blog post of mine swharden/SWHarden.com#27
Now arrays A, B, and r are defined for index "n-1" but array C is not. However, C[n-1] is required in the indicated for loop.
The referenced code is also in ScottPlot, here
ScottPlot/src/ScottPlot4/ScottPlot/Statistics/Interpolation/Cubic.cs
Lines 99 to 106 in 093994e
This issue will track better understanding this issue and coming up with a fix. I'll ping @drolevar in case they're interested in providing feedback, but they recently contributed some great related work in #3623 #3629
Adding more context, I think the issue may be that C[n-1]
never gets set in the loop above, so it's always 0
ScottPlot/src/ScottPlot4/ScottPlot/Statistics/Interpolation/Cubic.cs
Lines 85 to 95 in 093994e
Perhaps the fix is to add:
C[n - 1] = 1.0f / (x[n] - x[n-1]);