Skip to content

Instantly share code, notes, and snippets.

View sadrasabouri's full-sized avatar
🏠
Working from home

Sadra Sabouri sadrasabouri

🏠
Working from home
View GitHub Profile
@jcchurch
jcchurch / linear_regression.m
Created October 13, 2011 15:45
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