Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fitting an Akima Spline curve

I'm trying to fit an Akima Spline curve in C# using the same method as this tool: https://www.mycurvefit.com/share/4ab90a5f-af5e-435e-9ce4-652c95c3d9a7

This curve gives me the exact shape I'm after (the curve line peaking at X = 30M, the highest point from the sample data)

But when I use MathNet's Akima function, and plot 52 points from the same data set:

    var x = new List<double> { 0, 15000000, 30000000, 40000000, 60000000 };
    var y = new List<double> { 0, 93279805, 108560423, 105689254, 90130257 };

    var curveY = new List<double>();
    var interpolation = MathNet.Numerics.Interpolation.CubicSpline.InterpolateAkima(x.ToArray(), y.ToArray());

    for (int i=1; i<=52; i++)
    {
        var cY = interpolation.Interpolate((60000000/52)*i);
        curveY.Add(cY);
    }

I don't get the same curve at all, I get a curve which peaks around X = 26M, and looks much more like a Natural Spline: https://www.mycurvefit.com/share/faec5545-abf1-4768-b180-3e615dc60e3a

What is the reason the Akimas look so different? (especially in terms of peak)

like image 935
FBryant87 Avatar asked Dec 12 '25 02:12

FBryant87


1 Answers

Interpolate method waiting double parameter but this is integer (60000000 / 52) * i

change (60000000 / 52) * i to (60000000d / 52d) * i

enter image description here

like image 131
levent Avatar answered Dec 13 '25 15:12

levent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!