Gram-Schmidt Orthogonalization

Enter matrix dimensions $m \times n$, generate input matrix $A$, fill values, and calculate orthogonal and orthonormal bases using the Gram-Schmidt process.
(Columns of $A$ are the vectors. If linearly dependent, a subset will be used)

The Gram-Schmidt process converts a set of linearly independent vectors into an orthogonal (or orthonormal) set that spans the same subspace.

Algorithm:

Starting with vectors $\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_n$:

  • $\mathbf{u}_1 = \mathbf{v}_1$
  • $\mathbf{u}_k = \mathbf{v}_k - \sum_{j=1}^{k-1} \frac{\mathbf{v}_k \cdot \mathbf{u}_j}{\mathbf{u}_j \cdot \mathbf{u}_j} \mathbf{u}_j$ (orthogonal vectors)
  • $\mathbf{e}_k = \frac{\mathbf{u}_k}{\|\mathbf{u}_k\|}$ (orthonormal vectors)

Applications:

  • QR decomposition: $A = QR$ where $Q$ has orthonormal columns
  • Solving least squares problems
  • Finding orthonormal bases for subspaces
© 2025 Shelvean Kapita: kapita@tamu.edu
Last modified: December 16, 2025
Licensed under the MIT License.