c# – 使用Math.Net的基于指数的曲线拟合

我是Math.Net库的新手,我在尝试基于指数函数进行曲线拟合时遇到了问题.更具体地说,我打算使用这个功能
f(x) = a*exp(b*x) + c*exp(d*x)

使用MATLAB我得到了相当不错的结果,如下图所示:

MATLAB计算以下参数:

f(x) = a*exp(b*x) + c*exp(d*x)
Coefficients (with 95% confidence bounds):
a =   29.6       ( 29.49,29.71)
b =    0.000408  (  0.0003838,0.0004322)
c =   -6.634     ( -6.747,-6.521)
d =   -0.03818   ( -0.03968,-0.03667)

是否可以使用Math.Net实现这些结果?

解决方法

没有看起来目前没有指数支持.然而,有一个关于Math.NET论坛的讨论,其中维护者提出了一个解决方法

https://discuss.mathdotnet.com/t/exponential-fit/131

案例链接中的内容重复:

You can,by transforming it,similar to Linearizing non-linear models
by transformation. Something along the lines of the following should
work:

double[] Exponential(double[] x,double[] y,DirectRegressionMethod method = DirectRegressionMethod.QR)
{
    double[] y_hat = Generate.Map(y,Math.Log);
    double[] p_hat = Fit.LinearCombination(x,y_hat,method,t => 1.0,t => t);
    return new[] {Math.Exp(p_hat[0]),p_hat[1]}; 
}

Example usage:

double[] x = new[] { 1.0,2.0,3.0 };
double[] y = new[] { 2.0,4.1,7.9 };
double[] p = Exponential(x,y); // a=1.017,r=0.687
double[] yh = Generate.Map(x,k => p[0]*Math.Exp(p[1]*k)) // 2.02,4.02,7.98

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...