声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1582|回复: 1

[编程技巧] 非线性最小二乘拟合问题

[复制链接]
发表于 2009-8-26 16:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
请问非线性最小二乘拟合编程,我好像求就是求不出来,请各位高手帮忙


function y=myfun(abc,t)
y=abc(1)/(1+abc(2)*exp(-abc(3)*t))^(1/abc(4));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%主程序如下
t=[0,1,2,3];
y=[2.010,1.210,1.740,0.450];
[A,res]=lsqcurvefit('zhidao_aacceedd123',ones(1,4),t,y);  
L=A(1)
u=A(2)
b=A(3)
fi=A(4)
%%%%%%%%%%%%%%%%%%
运行后,显示如下:
??? Error using ==> optim\private\lsqncommon
User supplied function failed with the following error:
Attempted to access abc(3); index out of bounds because numel(abc)=2.
Error in ==> lsqcurvefit at 149
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> Untitled2 at 3
[A,res]=lsqcurvefit('myfun',ones(1,2),t,y);  
%%%%%%%%%
不知道什么意思,还请各位高手帮忙看看啊
回复
分享到:

使用道具 举报

发表于 2009-8-31 11:55 | 显示全部楼层
运行后怎么不是LZ显示的提示?
我电脑上提示是:
??? Error using ==> mpower
Matrix must be square.

Error in ==> myfun at 2
y=x(1)/(1+x(2)*exp(x(3)*xdata))^x(4);

Error in ==> lsqcurvefit at 209
            initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});

Caused by:
    Failure in initial user-supplied objective function evaluation. LSQCURVEFIT
    cannot continue.

原因是 ^运算引起的,若矩阵A^B,A必须是方阵,这个例子不涉及到上面的情况,我把fun都改成点运算,结果如下:
xdata=[0,1,2,3];
ydata=[2.010,1.210,1.740,0.450];
x0=ones(4,1);
[x,resnorm] = lsqcurvefit(@myfun,x0,xdata,ydata)
Maximum number of function evaluations exceeded;
increase options.MaxFunEvals

x =

    2.4575
    0.0073
    0.5028
   36.6275


resnorm =

    0.5454

M文件如下:
function y=myfun(x,xdata)
y=x(1)./(1+x(2).*exp(x(3).*xdata)).^x(4);
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-11 16:43 , Processed in 0.075696 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表