Skip to content

Instantly share code, notes, and snippets.

@jcchurch
Created October 13, 2011 15:45
Show Gist options
  • Save jcchurch/1284580 to your computer and use it in GitHub Desktop.
Save jcchurch/1284580 to your computer and use it in GitHub Desktop.
Linear Regression in Matlab
function [m b] = linear_regression(X, Y)
n = length(Y);
EX = sum(X);
EY = sum(Y);
EX2 = sum(X.*X);
EXY = sum(X.*Y);
m = (n*EXY - EX*EY) / (n*EX2 - EX*EX);
b = (EY - m*EX) / n;
end
@sadrasabouri
Copy link

Working nice.
Understandable enough for anyone to use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment