%
% Data points representing height and weight of certain
% people
%

pt1 = [65, 130];
pt2 = [68, 170];
pt3 = [67, 170];
pt4 = [74, 170];
pt5 = [71, 160];
pt6 = [72, 160];

%
% Make A u = c
% where                                [ y1 ]
%        [ x1 1 ]                      [ y2 ]
%   A =  [ x2 1 ], u = [a; b] and c =  [ y3 ]
%        [ x3 1 ]		       [ y4 ]
%				       [ y5 ]

P = [pt1; pt2; pt3; pt4; pt5; pt6];

samplesize = rows(P)

A = [P(:,1), ones(samplesize,1)]

c = P(:,2)

%
% We will solve the problem using pseudo-inverse of A
% produced by pinv(A)
%
u = pinv(A) * c

%
% These are the slope and intercept of the "best" linear
% model
%             weight = a * height + b
%

a = u(1)

b = u(2)

% Now, a prediction of weight of a person 64 inches tall
%
% [64 1] * u
% P1 * u if P1 is data for many people NOT in my original sample.
%

a * 64 + b 

%
% Sample standard deviation
%
norm(A*u-c)/sqrt(samplesize)
