No BSD License  

Highlights from
advstat

advstat

by

 

10 Nov 2000 (Updated )

Adds some additional capabilities to the Stats TB

CURVEFITEG1
 function CURVEFITEG1
 % leasq example using lsqcurvefit
% generate some data
% modified for 5.3 4-28-99, 6.1 8-22-01

t=[0.:.01:1]';
p=[4 5];
y=exp(-p(1)*t).*sin(2*pi*p(2)*t);
yd=y+.01*randn(size(y));  %add noise
p0=[2	3];	  %initial guess for paprameters
[pfinal,resn,error,exf,out,l,jac]=lsqcurvefit(@modelcurve,p0,t,yd);
pfinal
ymodel=yd+error; %reshape(error,size(yd));% error vector needs reshaping-may not be necessary

% calc regression data
[std,varresid,r2,cor,vcv,varinf]=regdata(pfinal,ymodel,yd,jac);
figure
plot(t,ymodel,t,yd,'o')
grid
xlabel('time t');ylabel('y ')
title('fitted - , vs data o')
%=================
function y=modelcurve(p,t)
y=exp(-p(1)*t).*sin(2*pi*p(2)*t);
return

Contact us