2.

a. Linear Regression:

This Problem was solved using matlab and the code for the solution is present in file hw2part2a.m.
Below derivation was used for getting to the formula for calculating the least squares