MATLAB函数拟合使用

本文详细介绍了MATLAB中的函数拟合,包括使用fit命令进行命令行拟合,通过界面启动拟合工具箱进行图形化操作,以及如何选择拟合类型和查看拟合结果。在拟合过程中,可以通过调整拟合类型、阶数和鲁棒性来优化拟合效果。拟合结果的各项性能指标可用于评估拟合质量。

1 函数命令拟合

最常用的函数拟合命令为fit,语法为|

[拟合结果 拟合精度]=fit(X数据,Y数据,‘拟合类型’)

其中,具体的拟合类型可以参看帮助文档,也可以使用fittype来自定义新的函数类型,比如定义拟合函数a*x+b*x^2+exp(4*x);|

newtype=fittype('a*x+b*x^2+exp(4*x)') ;
fit(x,y,newtype);

x=[1;2;3;4;5];
y=[2;3;4;5;6]; 

2 使用界面启动拟合工具箱

在这里插入图片描述

具体操作步骤

  1. 在APP一栏,选择curve fitting工具箱,然后选择相应阶段的数据,填入X dataY data
  2. fit options一栏选择对应的函数形式,阶数,和鲁棒性
  3. 点击工具栏的residuals plot,便于观察拟合误差
  4. 点击工具栏的data cursor,可以用鼠标在曲线上标记出具体的坐标值

3 界面介绍

在这里插入图片描述

  • 顶部为常用工具栏,常用的一般有误差分析和鼠标标记坐标点
  • Fit Options可以选择拟合类型和函数次数
  • 左侧Results显示了拟合结果的性能参数
  • 底部的table of fits可以对多个不同的拟合结果进行性能比较

4 拟合类型

在这里插入图片描述

拟合类型解释
Custom Equations用户自定义的函数类型
Exponentialexp指数逼近,有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种类型,linearnearest neighborcubic splineshape-preserving
Polynomial多形式逼近,有9种类型,linear ~quadratic ~cubic ~4-9th degree ~
Power幂逼近,有2种类型,a*x^ba*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)

5 拟合结果说明

例如在上面的拟合中,选择Polynomial类型,Degree选择3阶,Robust选择Off,得到的Results如下:

Linear model Poly3:
     f(x) = p1*x^3 + p2*x^2 + p3*x + p4
Coefficients (with 95% confidence bounds):
       p1 =   0.0007776  (0.0007486, 0.0008066)
       p2 =      -0.121  (-0.1258, -0.1161)
       p3 =       6.324  (6.055, 6.592)
       p4 =        -107  (-111.9, -102)

Goodness of fit:
  SSE: 0.555
  R-square: 0.9973
  Adjusted R-square: 0.9973
  RMSE: 0.03777

其中,Goodness of fit里面的性能指标如图所示:

性能指标解释
SSEThe 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-squareThe 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-squareThe 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.
RMSEThe root mean squared error. A value closer to 0 indicates a better fit.

6 参考文献

  1. 函数拟合工具包 [Fudan Physics Teaching Lab]
    http://phylab.fudan.edu.cn/doku.php?id=howtos:matlab:mt1-5
  2. Matlab的曲线拟合工具箱CFtool使用简介 - yousun - 博客园
    https://www.cnblogs.com/yousun/p/3450676.html
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值