Skip to content

Instantly share code, notes, and snippets.

@jcchurch
Created October 13, 2011 15:45
Show Gist options
  • Select an option

  • Save jcchurch/1284580 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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