|
连x和y都不同维你就敢拿上来作例子问问题...
- function ExpFitSolve
- clc
- x=[0.1:0.1:1];
- y=[0 10 30 45 53 64 74 82 90 96];
- str=['a(1)*exp(a(2)*x)+a(3)*exp(a(4)*x)+a(5)*exp(a(6)*x)'];
- ff=inline(str,'a','x');
- a0 =[-300,-5,200,-1,-40,0]; % Starting guess
- [a,resnorm] = lsqcurvefit(ff,a0,x,y)
- str1=[num2str(a(1)),'*exp(',num2str(a(2)),'*x)+',num2str(a(3)),'*exp(',num2str(a(4)),'*x)+',...
- num2str(a(5)),'*exp(',num2str(a(6)),'*x)'];
- ff1=inline(str1,'x');
- xx=linspace(0.1,1);
- plot(xx,ff1(xx),x,y,'r*')
复制代码
运行结果:
- Optimization terminated: relative function value
- changing by less than OPTIONS.TolFun.
- a =
- -215.6447 -0.9299 217.4042 -0.1350 -21.9148 -0.9272
- resnorm =
- 33.1770
复制代码
假如不知道各个拟合参数的具体意义的话,这种问题用1stopt最方便,用MATLAB猜测初值都累死了!
- Title "Type your title here";
- Parameters p(1:6);
- //Variable ;
- Function y=p1*exp(p2*x)+p3*exp(p4*x)+p5*exp(p6*x);
- data;
- //x y
- 0 0
- .1 10
- .2 30
- .3 45
- .4 53
- .5 64
- .6 74
- .7 82
- .8 90
- .9 96
- 1.0 103
复制代码
运行结果:
- p1 -204.397990804389
- p2 -0.940369929518947
- p3 225.924142434237
- p4 -0.105081317615115
- p5 -23.3984698872791
- p6 -0.105081295787684
复制代码
[ 本帖最后由 bainhome 于 2006-8-29 01:29 编辑 ] |
评分
-
1
查看全部评分
-
|