%example of least squares linear approximation

a = [2;3;4];
b = [1;2;4];   %data points are {(a_i,b_i)}

A = [1,a(1);1,a(2);1,a(3)];
A_t = transpose(A);

c = linsolve(A_t*A,A_t*b)   %c = solution to A_t*A*c = A_t*b

plot(a,b,'or')              %plots data points
line([1,5],[c(1)+c(2),c(1)+c(2)*5])   %plots linear approximation on [1,5]