MATLAB polyfit功能不起作用

时间:2014-03-15 15:05:02

标签: matlab curve-fitting data-fitting

由于某些原因,polyfit函数不断给我NaN我的功能,我根本不理解,因为当使用另一个功能时,它工作得很好。这是我的代码:

lb=0; %lowerbound of data 
ub=10; %upperbound of data 
step=.001; %step-size through data 
a=.03; 
la=1482/120000; %1482 is speed of sound in water and 120kHz
ep1=.1;
ep2=.2;
x=lb:step:ub;
r_sq_des=0.99; %desired value of r^2 for the fit of data without noise 
 %present 
%  G = abs(sin((a/la)*pi.*x.*(sqrt(1+(1./x).^2)-1)));
%  r=x;

i=1; 

for x=lb:step:ub 
 G(i,1)= abs(sin((a/la)*pi*x*(sqrt(1+(1/x)^2)-1)));
%  N(i,1)=2*rand()-1; 
%  Ghat(i,1)=(1+ep1*N(i,1))*G(i,1)+ep2*N(i,1); 
 r(i,1)=x; 
 i=i+1; 
end

 Q=polyfit(r,G,2); %Polynomial fit of the data G(r) w.o. noise 
 Z=polyval(Q,r); %Evaluation of the polynomial fit for the data w.o.noise 

请告知。

0 个答案:

没有答案