3

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)

Peter O.
  • 32,158
  • 14
  • 82
  • 96
FBryant87
  • 4,273
  • 2
  • 44
  • 72

2 Answers2

1

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

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

enter image description here

levent
  • 3,464
  • 1
  • 12
  • 22
  • That's a good spot, but doesn't change things much (the generated curve is still miles off the given desired Akima example) – FBryant87 Mar 07 '17 at 15:03
1

I gave up with the MathNet functions and used the CubicSpline.FitParametric() function on this implementation instead: https://www.codeproject.com/Articles/560163/Csharp-Cubic-Spline-Interpolation

This successfully gave me the desired fit I was after (which fully respects the sample data peak).

Peter O.
  • 32,158
  • 14
  • 82
  • 96
FBryant87
  • 4,273
  • 2
  • 44
  • 72