function [A,b] = LSRegression(X,Y) [D,N] = size(X); EX = sum(X,2)/N; CovX = X*X'/N - EX*EX'; EY = sum(Y,2)/N; CovXY = Y*X'/N - EY*EX'; A = CovXY * inv(CovX); b = EY - A*EX; figure(1);clf; minX = min(X(1,:)); maxX = max(X(1,:)); x=minX:0.01:maxX; plot(X(1,:),Y(1,:),'o');hold on; plot(x,A(1,1)*x+b(1),'r-'); drawnow;