matlab lsqcurvefit 曲线拟合时程序老出错
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/09/04 13:05:01
matlab lsqcurvefit 曲线拟合时程序老出错
程序如下:
function f =curvefun(x,XDATA)
f = x(1)*log10(1 + 1/(x(2)+XDATA.^x(3)));
主程序为:
XDATA = [1,2,3,4,5,6,7,8,9];
YDATA = [0.726,0.151,0.055,0.028,0.018,0.009,0.005,0.003,0.003];
x0 = [0.1 -1 0.1];
[x,res] = lsqcurvefit(@curvefun,x0,XDATA,YDATA);
错误提示为:
Error using ==> lsqncommon at 101
LSQCURVEFIT cannot continue because user supplied objective function failed with the following error:
Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> lsqcurvefit at 186[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> test1 at 4[x,res] = lsqcurvefit(@curvefun,x0,XDATA,YDATA);
程序如下:
function f =curvefun(x,XDATA)
f = x(1)*log10(1 + 1/(x(2)+XDATA.^x(3)));
主程序为:
XDATA = [1,2,3,4,5,6,7,8,9];
YDATA = [0.726,0.151,0.055,0.028,0.018,0.009,0.005,0.003,0.003];
x0 = [0.1 -1 0.1];
[x,res] = lsqcurvefit(@curvefun,x0,XDATA,YDATA);
错误提示为:
Error using ==> lsqncommon at 101
LSQCURVEFIT cannot continue because user supplied objective function failed with the following error:
Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> lsqcurvefit at 186[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> test1 at 4[x,res] = lsqcurvefit(@curvefun,x0,XDATA,YDATA);
%错误在 function 内:
% 1. 向量乘除要加点;
% 2. 除零情况未处理.
function f =curvefun(x,XDATA)
xx=x(2)+XDATA.^x(3);
f = x(1).*log10(1 + 1./(xx+eps*(xx==0)));
% 代码仅供参考
% 1. 向量乘除要加点;
% 2. 除零情况未处理.
function f =curvefun(x,XDATA)
xx=x(2)+XDATA.^x(3);
f = x(1).*log10(1 + 1./(xx+eps*(xx==0)));
% 代码仅供参考