linear_regression

# linear_regression - for i=1:n yi=y(i xi=x(i...

This preview shows pages 1–2. Sign up to view the full content.

function linear_regression(x,y) %Problem 13.5 %generates a graph of experimental data with a 'best fit' line n=numel(x); maxs=max(x); xold=0; yold=0; xi2old=0; yixi_old=0; srold=0; St_old=0; ysum=sum(y)/n; xsum=sum(x)/n; for i=1:n xnew=x(i); xi=xnew+xold; xold=xi; ynew=y(i); yi=ynew+yold; yold=yi; yixi=x(i)*y(i); yixi=yixi+yixi_old; yixi_old=yixi; xi2=x(i)^2; xi2=xi2+xi2old; xi2old=xi2; St=(ysum-y(i))^2+St_old; St_old=St; end a1=(n*yixi-xi*yi)/(n*xi2-xi^2); ao=ysum-a1*xsum;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for i=1:n yi=y(i); xi=x(i); Sr=(yi-ao-a1*xi)^2; Sr=Sr+srold; srold=Sr; end x3=[0:.1:maxs]'; y2=ao+a1*x3; %Standard Error of the estimate sxy=sqrt(Sr/(n-2)) %correlation coefficient r=sqrt((St-Sr)/St) fprintf('y=%7.6f+%7.6fx\n\n',ao,a1); if x(1)==0 AXIS=([0 20 0 12]); plot(x,y,'s',x3,y2) hold on else plot(x3,y2); end %--------------------------------------------------------------------------...
View Full Document

## This note was uploaded on 09/27/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

### Page1 / 2

linear_regression - for i=1:n yi=y(i xi=x(i...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online