Gram-Schmidt decomposition

This has come up before. You might look at this and this