%mathpiper,def="OrthonormalBasis"

// Like orthogonalization, only normalize all vectors
Function("OrthonormalBasis",{W})[
	Local(i);
	W:=OrthogonalBasis(W);
	For(i:=1,i<=Length(W),i++)[
		W[i]:=W[i]/Norm(W[i]);
	];
	W;
];

%/mathpiper



%mathpiper_docs,name="OrthonormalBasis",categories="User Functions;Linear Algebra"
*CMD OrthonormalBasis --- create an orthonormal basis 
*STD
*CALL
	OrthonormalBasis(W)

*PARMS

{W} - A linearly independent set of row vectors (aka a matrix)

*DESC

Given a linearly independent set {W} (constructed of rows vectors),
this command returns an orthonormal basis {V} for {W}. This is done
by first using {OrthogonalBasis(W)}, then dividing each vector by its
magnitude, so as the give them unit length. 

*E.G.

In> OrthonormalBasis({{1,1,0},{2,0,1},{2,2,1}})
Result: {{Sqrt(1/2),Sqrt(1/2),0},{Sqrt(1/3),-Sqrt(1/3),Sqrt(1/3)},
		{-Sqrt(1/6),Sqrt(1/6),Sqrt(2/3)}};

*SEE OrthogonalBasis, InProduct, Normalize
%/mathpiper_docs