stevensu27
2012-03-29, 14:39
问题是这样的,现在需要将http://www.ilovematlab.cn/data/attachment/forum/201203/29/141202pfpp2bk9o9y8wpb6.jpg这个函数加一些噪声进去,然后再用http://www.ilovematlab.cn/data/attachment/forum/201203/29/14131555yzrp4ptzyyw75a.jpg进行拟合,观察系数a1a2a3。现在噪声暂时还没有添加,程序如下
clear all
clf
x=-120:1:120;%x的取值范围
N=length(x);%x的向量长度
%A=(pi/1.54)-(pi/1.56)=0.0262;
y=((0.0262*x).^-1).*sin(0.0262*x);%产生y
plot(x,y)
f=inline('a(1)*((0.0262*(x-a(2))).^-1).*sin(0.0262*(x-a(2)))+a(3)','a','x');
[xx,res]=lsqcurvefit(f,[1,0,0],x,y); xx',res
运行一直不成功,返回下列结果
??? Error using ==> optim\private\snls
lsqcurvefit cannot continue: user function is returning Inf or NaN values.
Error in ==> optim\private\lsqncommon at 222
[x,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msg]=...
Error in ==> lsqcurvefit at 149
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
请问下这个的问题大概在哪里?应该怎么改?请帮我看看,非常感谢!!!!
clear all
clf
x=-120:1:120;%x的取值范围
N=length(x);%x的向量长度
%A=(pi/1.54)-(pi/1.56)=0.0262;
y=((0.0262*x).^-1).*sin(0.0262*x);%产生y
plot(x,y)
f=inline('a(1)*((0.0262*(x-a(2))).^-1).*sin(0.0262*(x-a(2)))+a(3)','a','x');
[xx,res]=lsqcurvefit(f,[1,0,0],x,y); xx',res
运行一直不成功,返回下列结果
??? Error using ==> optim\private\snls
lsqcurvefit cannot continue: user function is returning Inf or NaN values.
Error in ==> optim\private\lsqncommon at 222
[x,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msg]=...
Error in ==> lsqcurvefit at 149
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
请问下这个的问题大概在哪里?应该怎么改?请帮我看看,非常感谢!!!!