Matlab的曲线拟合工具箱CFtool使用简介 - 小众知识

Matlab的曲线拟合工具箱CFtool使用简介

2014-07-18 07:18:34 苏内容
  标签: Matlab/拟合/曲线
阅读:3449

http://phylab.fudan.edu.cn/doku.php?id=howtos:matlab:mt1-5


一、    单一变量的曲线逼近
Matlab有一个功能强大的曲线拟合工具箱 cftool ,使用方便,能实现多种类型的线性、非线
性曲线拟合。下面结合我使用的 Matlab R2007b 来简单介绍如何使用这个工具箱。
假设我们要拟合的函数形式是 y=A*x*x + B*x, 且A>0,B>0 。
1、在命令行输入数据:

》x=[110.3323 148.7328 178.064 202.8258033 224.7105 244.5711 262.908 280.0447
296.204 311.5475]

》y=[5 10 15 20 25 30 35 40 45 50]
 
2、启动曲线拟合工具箱
》cftool
 
3、进入曲线拟合工具箱界面“Curve Fitting tool”
(1)点击“Data”按钮,弹出“Data”窗口;
(2)利用X data和Y data的下拉菜单读入数据x,y,可修改数据集名“Data set name”,然
后点击“Create data set”按钮,退出“Data”窗口,返回工具箱界面,这时会自动画出数
据集的曲线图;
(3)点击“Fitting”按钮,弹出“Fitting”窗口;
(4)点击“New fit”按钮,可修改拟合项目名称“Fit name”,通过“Data set”下拉菜单
选择数据集,然后通过下拉菜单“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)
选择好所需的拟合曲线类型及其子类型,并进行相关设置:
——如果是非自定义的类型,根据实际需要点击“Fit options”按钮,设置拟合算法、修改
待估计参数的上下限等参数;
——如果选Custom Equations,点击“New”按钮,弹出自定义函数等式窗口,有“Linear
Equations线性等式”和“General Equations构造等式”两种标签。
在本例中选Custom Equations,点击“New”按钮,选择“General Equations”标签,输入函
数类型y=a*x*x + b*x,设置参数a、b的上下限,然后点击OK。
(5)类型设置完成后,点击“Apply”按钮,就可以在Results框中得到拟合结果,如下例:
general model:
f(x) = a*x*x+b*x
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.
 

扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1