% Igor Yanovsky
% Teaching Assistant
% Math 151B
% 05/29/07
% Driver routine:
% (1) calls Gram-Schmidt routine gsqr();
% (2) solves the linear least squares problem;
% (3) finds the error E = ||Au - b||_2.

clear all

A = [1 1 1; 1 2 4; 1 4 16; 1 5 25]
[Q,R] = gsqr(A)

b = [2 3 5 6]'
u = inv(R) * Q' * b

error = A*u - b
E = norm(error,2)      % Computes L2 norm of a vector error

clear all