Linear Regression in MATLAB (Least Square Regression)

Code:

 x=[2 3 5 7 9 ];
 y=[ 4 5 7 10 15 ];
 stem(x,y);
a=[];
for i=1:length(x)
    a=[a ; x(i) 1];
end
 c =a\y';
yR = c(1)*x + c(2); % the fitted line
hold on;
plot(x,yR);

No comments