拟合Akima样条曲线

时间:2017-03-07 14:37:37

标签: c# curve-fitting mathnet

我尝试使用与此工具相同的方法在C#中拟合Akima Spline曲线:https://www.mycurvefit.com/share/4ab90a5f-af5e-435e-9ce4-652c95c3d9a7

这条曲线给出了我之后的精确形状(曲线在X = 30M达到峰值,是样本数据的最高点)

但是当我使用MathNet的Akima函数时,从相同的数据集中绘制52个点:

    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);
    }

我根本没有得到相同的曲线,我得到的曲线在X = 26M附近达到峰值,看起来更像是自然样条曲线:https://www.mycurvefit.com/share/faec5545-abf1-4768-b180-3e615dc60e3a

Akimas看起来如此不同的原因是什么? (特别是在峰值方面)

2 个答案:

答案 0 :(得分:1)

插值方法等待双参数,但这是整数(60000000/52)* i

(60000000 / 52) * i更改为(60000000d / 52d) * i

enter image description here

答案 1 :(得分:1)

我放弃了MathNet函数并在此实现上使用了CubicSpline.FitParametric()函数:https://www.codeproject.com/Articles/560163/Csharp-Cubic-Spline-Interpolation

这成功地让我得到了我想要的适合度(完全尊重样本数据峰值)。

相关问题