vs选择工具->NuGet包管理器->程序包管理器控制台->输入Install-Package MathNet.Numerics进行安装
//如果是一次线性的话,走这里
if (m_order_num == (int)OrderEnum.one)
{
Tuple<double, double> s = new Tuple<double, double>(0, 0);
s = Fit.Line(X_arr, Y_arr);
//y = k*x+b
double b = s.Item1;
double k = s.Item2;
calc_arr = new double[2];
calc_arr[0] = b;
calc_arr[1] = k;
}
//2次或者3次的话走这里
else if (m_order_num == (int)OrderEnum.two || m_order_num == (int)OrderEnum.three)
{
calc_arr = Fit.Polynomial(X_arr, Y_arr, m_order_num);
}
double[] res = Fit.Polynomial(X, Y, m);
X是x轴数组,Y是y轴数组,m是次方,得到的res数组是从低次到高次排列的
例如4次方 则为 y=res[4]*x*x*x*x + res[3]*x*x*x + res[2]*x*x + res[1]*x + res[0]