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)报错:E

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 06:02:37

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)报错:E
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函数报错问题函数程序: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)报错:E
你自己定义的函数用到了a[3],但是你给的那个a0只有两项,他不知道该怎么办了.