www.pudn.com > 87361026FEA.rar > convergence.m, change:2002-10-01,size:581b


function convRate = convergence(h,error,lcolor,mtype); 
 
% function r = convergence(h,error,lcolor,mtype); 
% 
% compute the convergence rate and make a plot on the currently active 
% figure 
 
if ( nargin < 4 ) 
  mtype = 'o'; 
end 
 
if ( nargin < 3 ) 
  lcolor = 'r'; 
end 
 
% fit data 
useData=1:4; 
fit=polyfit(log(h(useData)),log(error(useData)),1); 
convRate=fit(1); 
c=exp(fit(2)); 
 
disp(['CONVERGENCE RATE: ',num2str(convRate)]) 
 
% plot data and fits 
clf 
loglog(h,error,[lcolor,mtype]) 
hold on 
loglog(h,c*h.^convRate,[lcolor,'--']) 
grid on 
[lcolor,'--',mtype]