terican

Last verified · v1.0

Calculator · math

Gram Schmidt Orthonormalization Calculator

Compute orthonormal basis vectors from any two linearly independent 2D or 3D vectors using the Gram-Schmidt process. Ideal for linear algebra, machine learning, and physics.

FreeInstantNo signupOpen source

Inputs

Selected Gram-Schmidt Result

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Selected Gram-Schmidt Result

The formula

How the
result is
computed.

What Is Gram-Schmidt Orthonormalization?

The Gram-Schmidt process transforms a set of linearly independent vectors into an orthonormal basis — a collection of mutually perpendicular unit vectors that span the same subspace. Named after Danish mathematician Jorgen Pedersen Gram and German mathematician Erhard Schmidt, this algorithm is fundamental to numerical linear algebra, quantum mechanics, signal processing, and machine learning. The Harvey Mudd College Calculus Tutorials identify it as one of the most essential algorithms for constructing orthonormal sets from arbitrary vector collections.

The Gram-Schmidt Formula Explained

For two input vectors v1 and v2, orthonormalization proceeds in three well-defined stages. First, the initial vector is normalized to unit length. Second, the component of the second vector lying along the first is subtracted out. Third, the orthogonal remainder is normalized.

  • Stage 1 — Normalize the first vector: e1 = v1 / ‖v1
  • Stage 2 — Remove the projection of v2 onto v1: u2 = v2 − [(v2 · v1) / (v1 · v1)] v1
  • Stage 3 — Normalize the orthogonal remainder: e2 = u2 / ‖u2

The scalar ratio (v2 · v1) / (v1 · v1) is the orthogonal projection coefficient. Subtracting that scaled multiple of v1 from v2 guarantees u2 is perpendicular to v1. After normalization, the resulting pair satisfies e1 · e2 = 0 (orthogonality) and ‖e1‖ = ‖e2‖ = 1 (unit length), as established in the University of Connecticut Mathematics orthogonality and least squares notes.

Input Variable Reference

  • v1x, v1y, v1z — X, Y, and Z components of the first input vector. Set v1z = 0 for 2D problems.
  • v2x, v2y, v2z — X, Y, and Z components of the second input vector. Set v2z = 0 for 2D problems.
  • e1 — First orthonormal basis vector, obtained by dividing v1 by its magnitude.
  • u2 — Intermediate vector equal to v2 minus its projection onto v1.
  • e2 — Second orthonormal basis vector, obtained by normalizing u2.
  • Output selector — Specifies which scalar component of the orthonormal result to return (e.g., e1x, e1y, e2x, e2y).

Worked Numerical Example

Take the 2D vectors v1 = (1, 1, 0) and v2 = (1, 0, 0) and apply all three stages to obtain an orthonormal basis for the xy-plane.

Stage 1 — Normalize v1

Magnitude: ‖v1‖ = √(1² + 1²) = √2 ≈ 1.4142. First orthonormal vector: e1 = (1/√2, 1/√2, 0) ≈ (0.7071, 0.7071, 0).

Stage 2 — Subtract the Projection

Dot product: v2 · v1 = (1)(1) + (0)(1) = 1. Self-dot: v1 · v1 = 1 + 1 = 2. Projection coefficient = 1/2 = 0.5. Intermediate vector: u2 = (1, 0, 0) − 0.5 × (1, 1, 0) = (0.5, −0.5, 0).

Stage 3 — Normalize u2

Magnitude: ‖u2‖ = √(0.25 + 0.25) = 1/√2 ≈ 0.7071. Second orthonormal vector: e2 = (1/√2, −1/√2, 0) ≈ (0.7071, −0.7071, 0). Verification: e1 · e2 = (0.7071)(0.7071) + (0.7071)(−0.7071) = 0.5 − 0.5 = 0 ✓. Both vectors carry unit length ✓.

Classical vs. Modified Gram-Schmidt

The classical formulation above is mathematically exact but can accumulate floating-point rounding errors when input vectors are nearly parallel. The modified Gram-Schmidt algorithm updates projection coefficients sequentially after each subtraction step, dramatically reducing numerical error in ill-conditioned cases. For well-separated input vectors, both variants yield identical results. The University of Southern Mississippi study on numerical Gram-Schmidt orthonormalization and the Duke University Math 218D worksheet solutions provide rigorous treatment of both variants and their stability properties across higher-dimensional matrices.

Real-World Applications

  • Machine Learning (PCA): Principal Component Analysis uses orthonormal eigenvectors to decorrelate features and reduce dimensionality in datasets with thousands of variables.
  • QR Decomposition: Factoring a matrix A into orthogonal Q and upper-triangular R — central to least-squares regression and eigenvalue solvers — directly applies Gram-Schmidt to A's column vectors.
  • Quantum Mechanics: Valid quantum state vectors must form orthonormal sets; Gram-Schmidt constructs admissible basis states from arbitrary wave functions in Hilbert space.
  • Computer Graphics: Tangent-space normal mapping and per-frame camera orientation matrices require orthonormal frames recomputed via this process every render cycle.
  • Signal Processing: Orthonormal filter banks and wavelet transforms depend on orthonormal bases for efficient, lossless decomposition of audio and image signals used in MP3 and JPEG compression.

Reference

Frequently asked questions

What is the Gram-Schmidt orthonormalization process?
The Gram-Schmidt process is a linear algebra algorithm that converts a set of linearly independent vectors into an orthonormal basis — vectors that are mutually perpendicular and each carry length exactly 1. For two vectors v1 and v2, the method normalizes v1 to obtain e1, subtracts from v2 its projection onto v1 to isolate an orthogonal remainder u2, then normalizes u2 to produce e2. The result is a clean, coordinate-aligned orthonormal basis spanning the same subspace as the original input vectors.
What inputs does the Gram Schmidt calculator require?
The calculator accepts two vectors in 3D space, each defined by three scalar components: X, Y, and Z. For 2D problems — such as vectors lying in the xy-plane — set both Z components (v1z and v2z) to 0. The two input vectors must be linearly independent, meaning neither is a scalar multiple of the other. An output selector then specifies which scalar component of the resulting orthonormal basis to display, such as the X component of e1 or the Y component of e2.
What is the difference between orthogonal and orthonormal vectors?
Orthogonal vectors are perpendicular to one another — their dot product equals zero — but can have any magnitude. Orthonormal vectors satisfy a stronger constraint: each vector is both perpendicular to all others and has a magnitude of exactly 1. For example, (2, 0) and (0, 5) are orthogonal but not orthonormal, whereas (1, 0) and (0, 1) are orthonormal. Gram-Schmidt produces fully orthonormal vectors, which simplify subsequent calculations because projections reduce to bare dot products with no length-correction denominators.
Can the Gram-Schmidt calculator handle 2D vectors?
Yes. To orthonormalize 2D vectors, enter the X and Y components of each vector and set both Z components (v1z and v2z) to 0. The calculator treats the inputs as lying in the xy-plane and produces an orthonormal pair where the Z components of e1 and e2 are both 0. This covers the most common classroom use case and applies to 2D graphics, planar signal processing, and any linear algebra problem restricted to a two-dimensional subspace.
What happens if the two input vectors are linearly dependent?
If the input vectors are linearly dependent — for example v1 = (1, 2, 0) and v2 = (2, 4, 0), where v2 = 2 v1 — the Gram-Schmidt process breaks down at Stage 2. After subtracting the full projection, the intermediate vector u2 collapses to the zero vector, which has no defined direction and cannot be normalized to unit length. The calculator returns an undefined or zero result for e2. Always confirm that the two input vectors point in genuinely distinct directions before running orthonormalization.
Where is Gram-Schmidt orthonormalization used in real-world applications?
Gram-Schmidt orthonormalization appears across numerous disciplines. In machine learning, it underpins Principal Component Analysis, which projects high-dimensional datasets onto orthonormal principal components for dimensionality reduction. In numerical linear algebra, QR decomposition — used in least-squares regression and eigenvalue computation — applies Gram-Schmidt to a matrix's columns. Quantum mechanics constructs orthonormal basis states for Hilbert-space representations. Computer graphics uses orthonormal camera and tangent frames every render cycle, while signal processing relies on orthonormal filter banks for audio compression in MP3 and image compression in JPEG standards.