Given a matrix A (not neccessarily square) with independent columns, I was able to apply Gram-Schmidt iteration and produce an orthonormal basis for its columnspace (in the form of an orthogonal matrix Q) using Matlab's function qr
A=[1,1;1,0;1,2]
[Q,R] = qr(A)
and then
>> Q(:,1:size(A,2))
ans =
-0.577350269189626 -0.000000000000000
-0.577350269189626 -0.707106781186547
-0.577350269189626 0.707106781186547
You can verify that the columns are orthonormal
Q(:,1)'*Q(:,2) equals zero and
norm(Q(:,1)) equals norm(Q(:,2)) equals 1
Given a matrix that has independent columns (like A), is there a function in R that produces the (Gram-Schmidt) orthogonal matrix Q ?. R's qr
function doesn't produce an orthogonal Q.
A quick search via rseek.org leads to package far and its function
orthonormalization
which you could try.qr
works, but it uses a unique convention and produces aqr
object that you further operate on withqr.Q
andqr.R
:Is this the output you wanted?