麻烦matlab高手用lsqcurvefit函数帮我拟合一组数据。
0.8044,0.8044,0.8044,0.7872,0.7872,0.7872,0.7872,0.7708,0.7708,0.7708,0.7708,
0.7708,0.7551,0.7255,0.7115,0.6727,0.6599,0.6491,0.6379,0.6271,0.6271,0.6167,
0.6167,0.6066,0.6066,0.6066,0.5968,0.5968,0.5968,0.5873,0.5873,0.5873,0.5873]
x=[0.0833,0.1667,0.25,0.3333,0.4167,0.5,0.5833,0.6667,0.75,0.8333,0.9167,1,1.0833
,1.1667,1.25,1.3333,1.4167,1.5,1.5833,1.6667,1.75,1.8333,1.9167,2,6,9,22,34,46, 58,70,82,94,106,118,130,142,154,166,178,190,202,214,226].想用matlab里的lsqcurvefit拟合出下面这个函数,y=1/a+x/b+(1/c)*[1-exp(-c*x/d)]。a,b,c,d要求的大于0的。就这些条件了。麻烦哪位会的同学,帮我解决下,在线等- -哪里看不清的可以说下。谢谢了。。。 展开
我做了一下发现误差比较大,是不是我给的初值有问题,还是给的数据有问题,你可以参考下
function f=curvefun1(x,xdata)
% y=1/a+x/b+(1/c)*[1-exp(-c*x/d)]
f=1/x(1)+xdata/x(2)+(1/x(3))*(1-exp(-x(3)*xdata/x(4)));
运行:
clear;clc;
xdata=[0.0833,0.1667,0.25,0.3333,0.4167,0.5,0.5833,0.6667,0.75,...
0.8333,0.9167,1,1.0833,1.1667,1.25,1.3333,1.4167,1.5,1.5833,...
1.6667,1.75,1.8333,1.9167,2,6,9,22,34,46, 58,70,82,94,106,118,...
130,142,154,166,178,190,202,214,226];
ydata=[0.925,0.881,0.8604,0.8604,0.8409,0.8409,0.8409,0.8222,0.8222,0.8222,0.8044,...
0.8044,0.8044,0.8044,0.7872,0.7872,0.7872,0.7872,0.7708,0.7708,0.7708,0.7708,...
0.7708,0.7551,0.7255,0.7115,0.6727,0.6599,0.6491,0.6379,0.6271,0.6271,0.6167,...
0.6167,0.6066,0.6066,0.6066,0.5968,0.5968,0.5968,0.5873,0.5873,0.5873,0.5873];
x0=[5,3,5,2]; %初值
x=lsqcurvefit('curvefun1',x0,xdata,ydata)
f=curvefun1(x,xdata);
plot(xdata,ydata,'.')
hold on
plot(xdata,f,'.')
运行结果:
x =
1.0e+002 *
Columns 1 through 3
0.036322600853330 2.664204064307804 0.038239112150553
Column 4
0.000104652408479
对不起,我的错,我给的Y值有问题,Y值是:y=[0.0123,0.0129,0.0132,0.0132,0.0135,0.0135,0.0135,0.0138,0.0138,0.0138,0.0141,0.0141,0.0141,0.0141,0.0144,0.0144,0.0144,0.0144,0.0148,0.0148,0.0148,0.0148,0.0148,0.0151,0.0157,0.016,0.0169,0.0172,0.0175,0.0178,0.0181,0.018,0.0184,0.0184,0.0188,0.0188,0.0188,0.0191,0.0191,0.0191,0.0194,0.0194,0.0194,0.0194]
X值不变。麻烦你再看看,耽误你时间了,不好意思。
不是用CFTOOL拟合的,你应该不是用的lsqcurvefit拟合的吧,这个需要初始值的- -
用cftool可以自定义拟合方程,我把你的原始方程设成自定义拟合方程了,拟合之后完全不搭边,所以我换了指数拟合,感觉还好,所以我很怀疑你的数据和方程有联系吗。
我一般用lsqcurvefit拟合时,都是先用cftool拟合把初值找到,再编程的,但是发现完全不搭边,所以直接编程我感觉也拟合不出来,数据真没问题吗