一个MATLAB的作业题

来源:百度知道 编辑:UC知道 时间:2024/06/07 10:55:05
目标函数为:
function F=c2fcure(t,x)
F=t(1)*x+t(2)*(x.^2).*exp(-t(3)*x)+t(4);
输入命令为:
x=[0.1:0.1:1];
y=[2.3201,2.6470,2.9707,3.2885,3.6008,3.9090,4.2147,4.5191,4.8232,5.1275];
plot(x,y,'o',x,y)
f=optimset; f.RelX=1e-10; f.TolFun=1e-15;
t=lsqcurvefit('c2fcure',[1;1;1;1],x,y,[0,0,0,0],[],f)
y1=c2fcure(t,x); plot(x,y,x,y1,x,y,'o')

运行后得到一张图,但并没看到t的值.
MATLAB显示的是.
??? Error using ==> f:/matlab/toolbox/optim/private/lsqncommon
User supplied function ==> c2fcure
failed with the following error:

Error using ==> feval
Undefined function 'c2fcure'.

Error in ==> F:\MATLAB\toolbox\optim\lsqcurvefit.m
On line 129 ==> [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...

请问我出错在哪啊?
谢谢各位.

c2fcure没有存在c2fcure.m文件里,或者没有放在work目录下

Error using ==> feval
Undefined function 'c2fcure'.
函数没有在最后加上end,定义不完整

Error in ==> F:\MATLAB\toolbox\optim\lsqcurvefit.m
On line 129 ==> [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
lsqcurvefit的语法肯定出错了

x=[0.1:0.1:1];
y=[2.3201,2.6470,2.9707,3.2885,3.6008,3.9090,4.2147,4.5191,4.8232,5.1275];
plot(x,y,'o',x,y)
f=optimset( 'tolx',1e-10,'TolFun',1e-15);
t=lsqcurvefit('c2fcure',[1;1;1;1],x,y,[0,0,0,0],[],f) ;
y1=c2fcure(t,x);
plot(x,y,x,y1,x,y,'o')
你看看结果对不对

god