作业帮 > 综合 > 作业

matlab中lsqcurvefit函数报错问题

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/11 16:42:09
matlab中lsqcurvefit函数报错问题
函数程序:
function f=myfun(a,x)
f=a(1)*35*exp(a(2)*x+a(3)*x^2);
命令:
x=[11.6 12.8 14.1 14.4 13.9 13 12.4];
y=[-0.3 -1 -1.48 -1.16 -1.26 -0.67 -0.73];
a0=[0,0];
[x,Resnorm]=lsqcurvefit(@myfun,a0,x,y)
报错:
Error using ==> optim\private\lsqncommon at 98
LSQCURVEFIT cannot continue because user supplied objective function failed with the following error:
Attempted to access a(3); index out of bounds because numel(a)=2.
Error in ==> lsqcurvefit at 182
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
matlab中lsqcurvefit函数报错问题
你自己定义的函数用到了a[3],但是你给的那个a0只有两项,他不知道该怎么办了.