matlab如何拟合幂函数y=ax^b的程序

matlab如何拟合幂函数y=ax^b的程序,第1张

例7 用下面表6 中的扮漏数据拟合函数c(t) = a + be−0.02kt中的参数a,b, k 。

表6

j t 100 200 300 400 500 600 700 800 900 1000

j c 4.54 4.99 5.35 5.65 5.90 6.10 6.26 6.39 6.50 6.59

解 该问题即解最优化问题:

Σ=

− = + −姿饥

10

1

0.02 2 min ( , , ) ( )

i

j

kt F a b k a be j c

(1)编写M文件fun1.m定义函数F(x,tdata):

function f=fun1(x,tdata)

f=x(1)+x(2)*exp(-0.02*x(3)*tdata)%其中x(1)=a,x(2)=b,x(3)=k

(2)调用函数lsqcurvefit,编迹缺返写程序如下:

td=100:100:1000

cd=[4.54 4.99 5.35 5.65 5.90 6.10 6.26 6.39 6.50 6.59]

x0=[0.2 0.05 0.05]

x=lsqcurvefit(@fun1,x0,td,cd)

直接使用CFTOOL工具箱

命令行输入cftool即可,然后选择拟合类型

x=[6.69:0.02:7.53]

y=[4.2,3.7,3.3,2.95,2.63,2.33,2.11,1.87,1.65,1.47,1.32,1.17,1.04,0.925,0.82,0.735,0.653,0.582,0.52,0.462,0.412,0.366,0.325,0.289,0.258,0.23,0.205,0.182,0.162,0.145,0.129,0.115,0.102,0.091,0.081,0.072,0.064,0.057,0.051,0.0455,0.0403,0.036,0.032]

直接输入滑芹辩cftool进入曲线拟合工具箱界面首滑“Curve Fitting tool”

(1)点击“Data”按钮,d出“Data”窗口;

(2)利用X data和Y data的下拉菜单读入数据x,y,然后点击“Create data set”按钮,退出“Data”窗口,返回工具箱界面,这时会自动画出数据集的曲线图;

(3)点击“Fitting”按钮,d出“Fitting”窗口;

(4)点击“New fit”按钮,可修改拟合项目名称“Fit name”,通过“Data set”下拉菜单选择数据集,然后通过下拉菜单“Type of fit”选择拟合曲线的类型,选择类信缺型Power:幂逼近,有2种类型,a*x^b 、a*x^b + c

【代码】

x=[200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000]

y=[0.1 0.25 0.49 0.65 0.7 0.91 1.15 1.26 1.37 1.46 1.52 1.60 1.65 1.67 1.68 1.68 1.69 1.69 1.71]

cftool(x,y)

【拟合方式一:指数拟合】

General model Power2:

     f(x) = a*x^b+c

Coefficients (with 95% confidence bounds):

       a =      -44.95  (-570, 480.1)

       b =    -0.02049  (-0.297, 0.2561)

       c =        40.3  (-490, 570.6)

Goodness of fit:

  SSE: 0.1527

  R-square: 0.9708

  Adjusted R-square: 0.9672

  RMSE: 0.0977

【拟合方式二:最高三次多项式

Linear model Poly3:

     f(x) = p1*x^3 + p2*x^2 + p3*x + p4

Coefficients (with 95% confidence bounds):

       p1 = -1.208e-011  (-1.778e-010, 1.536e-010)

     桐棚祥  p2 = -6.613e-007  (-1.214e-006, -1.088e-007)

       p3 =    0.002397  (0.001855, 0.00294)

       p4 =      -0.388  (-0.5376, -0.2384)

Goodness of fit:

  SSE: 0.02784

  R-square: 0.9947

  Adjusted R-square: 0.9936

  RMSE: 0.04308

【拟合方式三:最高四次多项式】

Linear model Poly4:

     f(x) = p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5

Coefficients (with 95% confidence bounds):

       p1 =  4.099e-013  (1.256e-013, 6.942e-013)

       p2 = -1.815e-009  (-3.073e-009, -5.575e-010)

       p3 =  2.001e-006  (1.018e-007, 3.9e-006)

       p4 =   0.0009045  (-0.0002188, 0.002028)

       p5 =     -0.1391  (-0.3494, 0.07117)

Goodness of fit:

  SSE: 0.01654

  R-square: 0.9968

  Adjusted R-square: 0.9959

  RMSE: 0.03437

【小结和粗】

实际上多项式拟合经度(SSE,RMSE)四次高于三次,因为四次包含了三次,需要根据物理模型来确定选择多项式最高次数。

指数模型精度低于三次多项式。

本文希望你局搏能认识一个新的有用的函数,曲线拟合工具箱

希望你学习进步。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12406173.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存