Solution (source code)

= Solution

The <Gram-Schmidt process> constructs the vectors in order:
$$
v_j=x_j-\sum_{i<j}\langle q_i,x_j\rangle q_i,\qquad q_j=\frac{v_j}{\lVert v_j\rVert},\qquad j=1,\ldots,k.
$$
The empty sum at $j=1$ is zero. Each subtraction removes the projection onto one previous <unit vector>, so $v_j$ is orthogonal to their span. <Linear independence> of the inputs ensures $v_j\ne0$ in exact arithmetic, and normalization gives unit length.

In <floating-point arithmetic>, subtracting nearly equal projections can amplify roundoff and cause loss of orthogonality, especially for nearly dependent columns. <Modified Gram-Schmidt>, reorthogonalization, or <Householder QR factorization> can improve numerical behaviour; no implementation can remove the underlying sensitivity of nearly dependent input data.