wuhaowen211 发表于 2009-8-26 16:28

非线性最小二乘拟合问题

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


function y=myfun(abc,t)
y=abc(1)/(1+abc(2)*exp(-abc(3)*t))^(1/abc(4));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%主程序如下
t=;
y=;
=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
= ...
Error in ==> Untitled2 at 3
=lsqcurvefit('myfun',ones(1,2),t,y);
%%%%%%%%%
不知道什么意思,还请各位高手帮忙看看啊

heizaoniangao 发表于 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=;
ydata=;
x0=ones(4,1);
= 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);
页: [1]
查看完整版本: 非线性最小二乘拟合问题