% bases2D.m
% run this program several times, random data.
clear

% get two random vectors
v1=3*rand(2,1);
v2=3*rand(2,1);

% Make them orthogonal
v2o=v2-v1'*v2*v1/(v1'*v1);

% Make them orthonormal
v1on=v1/norm(v1);
v2on=v2o/norm(v2o);

% Get suitable scaling for plots
k=max([norm(v1) norm(v2) norm(v2o) 1]);
ax=[-k k -k k];

% Plot the stuff
figure(1), clf, axis(ax), axis equal, hold on
plot([0 v1(1)], [0 v1(2)], 'r', [0 v2(1)], [0 v2(2)], 'g')
plot(v1(1), v1(2), 'rp', v2(1), v2(2), 'gp')
title( 'Two random vectors - a basis for the plane')

figure(2), clf, axis(ax), axis equal, hold on
plot([0 v1(1)], [0 v1(2)], 'r', [0 v2o(1)], [0 v2o(2)], 'g')
plot(v1(1), v1(2), 'rp', v2o(1), v2o(2), 'gp')
title( 'The vectors made orthogonal - an orthogonal basis')

figure(3), clf, axis(ax), axis equal, hold on
plot([0 v1on(1)], [0 v1on(2)], 'r', [0 v2on(1)], [0 v2on(2)], 'g')
plot(v1on(1), v1on(2), 'rp', v2on(1), v2on(2), 'gp')
title(' The vectors made orthonormal - an orthonormal basis')


