Matlab 的曲线拟合工具箱 CFtool 使用 it 2010-04-06 11:24:00 阅读 98 评论 0 字号:大中小 订阅 下面结合我使用的 Matlab R2007b 来简单介绍如何使用这个工具箱。 假设我们要拟合的函数形式是 y=A*x*x + B*x, 且 A0,B0 。 1 、在命令行输入数据: 》 x= 》 y= 后点击 “Create data set” 按钮,退出 “Data” 窗口,返回工具箱界面,这时会自动画出数 选择数据集,然后通过下拉菜单 “Type of fit” 选择拟合曲线的类型,工具箱提供的拟合类 型有: Custom Equations :用户自定义的函数类型 Exponential :指数逼近,有 2 种类型, a*exp(b*x) 、 a*exp(b*x) + c*exp(d*x) Fourier :傅立叶逼近,有 7 种类型,基础型是 a0 + a1*cos(x*w) + b1*sin(x*w) Gaussian :高斯逼近,有 8 种类型,基础型是 a1*exp(-((x-b1)/c1)^2) Interpolant :插值逼近,有 4 种类型, linear 、 nearest neighbor 、 cubic spline 、 shape- preserving Polynomial :多形式逼近,有 9 种类型, linear ~ 、 quadratic ~ 、 cubic ~ 、 4-9th degree ~ Power :幂逼近,有 2 种类型, a*x^b 、 a*x^b + c Rational :有理数逼近,分子、分母共有的类型是 linear ~ 、 quadratic ~ 、 cubic ~ 、 4-5th degree ~ ;此外,分子还包括 constant 型 Smoothing Spline :平滑逼近(翻译的不大恰当,不好意思) Sum of Sin Functions :正弦曲线逼近,有 8 种类型,基础型是 a1*sin(b1*x + c1) Weibull :只有一种, a*b*x^(b-1)*exp(-a*x^b) Equations 线性等式 ” 和 “General Equations 构造等式 ” 两种标签。 在本例中选 Custom Equations ,点击 “New” 按钮,选择 “General Equations” 标签,输入函 数类型 y=a*x*x + b*x ,设置参数 a 、 b 的上下限,然后点击 OK 。 ( 5 )类型设置完成后,点击 “Apply” 按钮,就可以在 Results 框中得到拟合结果,如下例: Coefficients (with 95% confidence bounds): a = 0.009194 (0.009019, 0.00937) b = 1.78e-011 (fixed at bound) Goodness of fit: SSE: 6.146 R-square: 0.997 Adjusted R-square: 0.997 RMSE: 0.8263 同时,也会在工具箱窗口中显示拟合曲线。 这样,就完成一次曲线拟合啦,十分方便快捷。当然,如果你觉得拟合效果不好,还可以在 “ Fitting” 窗口点击 “New fit” 按钮,按照步骤( 4 ) ~ ( 5 )进行一次新的拟合。 不过,需要注意的是, cftool 工具箱只能进行单个变量的曲线拟合,即待拟合的公式中,变 量只能有一个。对于混合型的曲线,例如 y = a*x + b/x ,工具箱的拟合效果并不好。下一 篇文章我介绍帮同学做的一个非线性函数的曲线拟合。 以上内容出自: http://hi.baidu.com/snowlxm/blog/item/15a714b122ae95500823025f.html 上边对 cftool 工具箱做了很详尽的说明,但并没有对各种曲线拟合的性能做点评,在单变量曲线拟合中,如何选取一种最优化的拟合方式是非常重要的,我们在采用 CFTOOL 拟合后,会有一些性能说明,如: Goodness of fit: SSE: 6.146 R-square: 0.997 Adjusted R-square: 0.997 RMSE: 0.8263 官方的解释: Results -- Displays detailed results for the current fit including the fit type (model, spline, or interpolant), the fitted coefficients and 95% confidence bounds for parametric fits, and these goodness of fit statistics: SSE -- The sum of squares due to error. This statistic measures the deviation of the responses from the fitted values of the responses. A value closer to 0 indicates a better fit. R-square -- The coefficient of multiple determination. This statistic measures how successful the fit is in explaining the variation of the data. A value closer to 1 indicates a better fit. Adjusted R-square -- The degree of freedom adjusted R-square. A value closer to 1 indicates a better fit. It is generally the best indicator of the fit quality when you add additional coefficients to your model. RMSE -- The root mean squared error. A value closer to 0 indicates a better fit.