%% Exam Question 10
%
% Show that $v_1 = (\frac{2}{3},\frac{1}{3},\frac{2}{3})$ and $v_2 = (\frac{1}{3},\frac{2}{3},-\frac{2}{3})$ are orthonormal vectors and find a third vector $v_3$ for which $\{v_1,v_2,v_3\}$.

%% Hint 1: Check that v1 & v2 are orthogonal
v1 = [2/3 1/3 2/3]
v2 = [1/3 2/3 -2/3]

d12 = dot(v1,v2)

%% Hint 2: Verify that the norm of v1 and v2 equals 1.
n1 = norm(v1)
n2 = norm(v2)

%% Hint 3: How to solve a system of equations a1 - b2 + c4 = 0 and e5 + f2 + g3 = 0  for a,b,...g using MATLAB.
% Create an augented matrix, and find its reduced row echelon form. 
A = [1 -2 4 0; 5 2 3 0]
R = rref(A)

%% Solve a system of equations to find the coeffs (a,b,c) of v3
% 
% Define a matrix B whose entries are the coeffs of v1 and v2 together with zeros at end and do an rref.
B = [v1 0 ; v2 0]
R = rref(B)

%% How to read the rref
% The matrix above means that a + 2c = 0, and b - 2c = 0, and c is free.  Any nonzero choice of c will produce a vector orthongal to v1 and v2.  Let's choose c = 1.
w = [-2 2 1]

%% Normalize the solution vector. 
% Scale any vector by 1 over its length to get a normal vector
v3 = (1/norm(w)) * w

%% Finally check orthogonality, and normality
d13 = dot(v1,v3)
d23 = dot(v2,v3)
n3  = norm(v3)

