我想找到最适合非线性函数的系数,而非线性函数是一个积分函数。所以第一步是定义一个函数:
function dT = km(x,sT)
fun=@(temp)((-x(1)*x(2)*(temp).^(x(2)-1.0))./ ...
((x(3)^x(2))*((1+(temp./x(3)).^x(2)).^2)));
dT=integral(fun,0,sT);
% x is a array containing three coefficients;
% sT is a array containing integral upper limits;
$ dT is integral values;
然后lsqcurvefit
调用该函数以找到最佳系数:
x0=[0.0, 0.0, 0.0]; % initial coefficients;
x1=[300.0 -10.0 0.0]; % lower limit;
x2=[500.0 0.0 1000.0]; % upper limit;
stimeT=[1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0]; % XDATA
dmT=[3.0 6.0 9.0 12.0 15.0 18.0 21.0 24.0]; % YDATA
[x,resnorm]=lsqcurvefit(@km,x0,stimeT,dmT,x1,x2);
但我得到了这些错误:
Error using integral (line 86)
A and B must be floating point scalars.
Error in km (line 6)
dT=integral(fun,0.0,sT);
Error in lsqcurvefit (line 195)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in individual_kernel (line 57)
[x,resnorm]=lsqcurvefit(@km,x0,stimeT,dmT,x1,x2);
Caused by:
Failure in initial user-supplied objective function evaluation. LSQCURVEFIT
cannot continue.
MATLAB默认的数据类型是double,而double是浮点型,所以不知道怎么修改代码。任何建议将被认真考虑!