function [b,m] = linearRegression(x,y)
% linearRegression: Fits a line to a 2D data set using linear regression
% [b,m] = linearRegression(x,y) returns the y-intercept b and slope m of
% the best fit line through the data in x and y.
% Calculate the mean of x and y
xmean = mean(x);
ymean = mean(y);
% Calculate the terms needed for the linear regression
Num = sum((x - xmean).*(y - ymean));
Den = sum((x - xmean).^2);
% Calculate the slope and y-intercept
m = Num / Den;
b = ymean - m*xmean;
end