acalculator

What is the Gram-Schmidt basis?

Calculate Gram-Schmidt orthogonalization for vectors. Linear algebra and mathematics tool.

Your numbers

Vectors (one per row)
Rows are vectors; columns are their components.
Orthonormal basis
[0, 0.6, 0.8; 0.8574929257, -0.4115966043, 0.3086974533; -0.5144957554, -0.6859943406, 0.5144957554]

The orthonormal basis is [0, 0.6, 0.8; 0.8574929257, -0.4115966043, 0.3086974533; -0.5144957554, -0.6859943406, 0.5144957554].

u1
[0, 3, 4]
u2
[1, -0.48, 0.36]
u3
[-0.1764705882, -0.2352941176, 0.1764705882]
Working
u1 = v1 = [0, 3, 4], |u1| = 5, e1 = [0, 0.6, 0.8]; u2 = v2 − (0.8)e1 = [1, -0.48, 0.36], |u2| = 1.166190379, e2 = [0.8574929257, -0.4115966043, 0.3086974533]; u3 = v3 − (3)e1 − (1.371988681)e2 = [-0.1764705882, -0.2352941176, 0.1764705882], |u3| = 0.3429971703, e3 = [-0.5144957554, -0.6859943406, 0.5144957554]

Orthonormal basis: [0, 0.6, 0.8; 0.8574929257, -0.4115966043, 0.3086974533; -0.5144957554, -0.6859943406, 0.5144957554]. The orthonormal basis is [0, 0.6, 0.8; 0.8574929257, -0.4115966043, 0.3086974533; -0.5144957554, -0.6859943406, 0.5144957554].

How it is worked out

How to calculate

Runs the Gram-Schmidt process on up to 10 linearly independent vectors: the orthogonal vectors u₁, u₂, … and the orthonormal basis e₁, e₂, … that spans the same space, with the working.

Example with the default inputs (Vectors (one per row) [0, 3, 4; 1, 0, 1; 1, 1, 3]): The orthonormal basis is [0, 0.6, 0.8; 0.8574929257, -0.4115966043, 0.3086974533; -0.5144957554, -0.6859943406, 0.5144957554].

Method: u₁ = v₁; uₖ = vₖ − Σⱼ₍ⱼ₌₁…ₖ₋₁₎ (vₖ·eⱼ)eⱼ; eₖ = uₖ ÷ |uₖ|.

  • The vectors are real and linearly independent. A zero vector, or a vector that is a combination of the earlier ones, has no answer.
  • Vectors are processed in the order given; another order gives a different orthonormal basis of the same space.
  • A vector counts as dependent when the part of it outside the span of the earlier vectors is at most 10⁻¹⁰ of its length.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Vectors (one per row) 0, 3, 4; 1, 0, 1; 1, 1, 3 gives Orthonormal basis [0, 0.6, 0.8; 0.8574929257, -0.4115966043, 0.3086974533; -0.5144957554, -0.6859943406, 0.5144957554], u1 [0, 3, 4], u2 [1, -0.48, 0.36], u3 [-0.1764705882, -0.2352941176, 0.1764705882].Source: MIT OpenCourseWare 18.06 Linear Algebra (Gilbert Strang), Lecture 17: Orthogonal Matrices and Gram-Schmidt. https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/
  2. Vectors (one per row) 1, 1; 1, 0 gives Orthonormal basis [0.7071067812, 0.7071067812; 0.7071067812, -0.7071067812], u2 [0.5, -0.5].Source: MIT OpenCourseWare 18.06 Linear Algebra (Gilbert Strang), Lecture 17: Orthogonal Matrices and Gram-Schmidt. https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/
  3. Vectors (one per row) 1, 2, 3, 4; 4, 3, 2, 1 gives u2 [3.333333333, 1.666666667, 0, -1.666666667], Orthonormal basis [0.1825741858, 0.3651483717, 0.5477225575, 0.7302967433; 0.8164965809, 0.4082482905, 0, -0.4082482905].Source: MIT OpenCourseWare 18.06 Linear Algebra (Gilbert Strang), Lecture 17: Orthogonal Matrices and Gram-Schmidt. https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/
  4. Vectors (one per row) 2, 0, 0; 3, 4, 0; 5, 6, 7 gives Orthonormal basis [1, 0, 0; 0, 1, 0; 0, 0, 1], u2 [0, 4, 0], u3 [0, 0, 7].Source: MIT OpenCourseWare 18.06 Linear Algebra (Gilbert Strang), Lecture 17: Orthogonal Matrices and Gram-Schmidt. https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/
  5. Vectors (one per row) 3, 4, 0 gives Orthonormal basis [0.6, 0.8, 0], u1 [3, 4, 0].Source: MIT OpenCourseWare 18.06 Linear Algebra (Gilbert Strang), Lecture 17: Orthogonal Matrices and Gram-Schmidt. https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/

How it works

The Gram-Schmidt process takes linearly independent vectors v₁, v₂, …, vₖ and builds orthonormal vectors e₁, e₂, …, eₖ that span the same subspace:

  1. Start with the first vector: u₁ = v₁, and e₁ = u₁ ÷ |u₁|.
  2. For each next vector vᵢ, subtract its projection onto every earlier unit vector: uᵢ = vᵢ − (vᵢ·e₁)e₁ − … − (vᵢ·eᵢ₋₁)eᵢ₋₁.
  3. Normalize: eᵢ = uᵢ ÷ |uᵢ|, where |u| = √(u·u).

The vectors u₁, u₂, … are orthogonal; the vectors e₁, e₂, … are orthonormal. The calculator takes the vectors in the order you enter them (rows of the grid).

The page shows:

  • Orthonormal basis: e₁, e₂, … as rows separated by semicolons, for example [0, 0.6, 0.8; …].
  • u1, u2, …: the orthogonal vectors.
  • Working: each uᵢ with its projection coefficients vᵢ·eⱼ, its length, and eᵢ. The same text is listed step by step under "How it is worked out".

Numbers are rounded to 10 significant figures. A component within 10⁻¹² of 0 (relative to the length of the vector it comes from) is shown as 0. Negative numbers use a plain hyphen, such as -0.48. The projection coefficients in the working follow the same zero rule. Numbers of 10²¹ or more, or under 10⁻⁶ (other than 0), are written in e-notation, for example 1.4e+22 or 1.5e-7.

Assumptions

  • Up to 10 vectors, each with up to 10 real components.
  • The vectors must be linearly independent. When the part of vᵢ outside the span of the earlier vectors is at most 10⁻¹⁰ of |vᵢ| (for example a zero vector, or v₂ = 2v₁), there is no answer. More vectors than components are always dependent.
  • The page uses a numerically stable form of the same process (modified Gram-Schmidt, run twice), which gives the same vectors as the formulas above.
  • Old links from the previous version of this page (vectorCount, dimension, and cells v00 to v99) open the same vectors. A missing cell counts as 0.

Worked examples by hand

The default vectors v₁ = (0, 3, 4), v₂ = (1, 0, 1), v₃ = (1, 1, 3).

  • u₁ = (0, 3, 4), |u₁| = 5, so e₁ = (0, 0.6, 0.8).
  • v₂·e₁ = 0 + 0 + 0.8 = 0.8. u₂ = (1, 0, 1) − 0.8(0, 0.6, 0.8) = (1, −0.48, 0.36). |u₂| = √1.36 = 1.1661904, so e₂ = (0.8574929257, −0.4115966043, 0.3086974533).
  • v₃·e₁ = 0.6 + 2.4 = 3; v₃·e₂ = (1 − 0.48 + 1.08) ÷ 1.1661904 = 1.6 ÷ 1.1661904. u₃ = v₃ − 3e₁ − (1.6 ÷ 1.36)u₂ = (1, 1, 3) − (0, 1.8, 2.4) − (1.1764706, −0.5647059, 0.4235294) = (−0.1764705882, −0.2352941176, 0.1764705882), which is (−3, −4, 3)/17. |u₃| = √34/17, so e₃ = (−3, −4, 3)/√34 = (−0.5144957554, −0.6859943406, 0.5144957554).

Two vectors in the plane v₁ = (1, 1), v₂ = (1, 0). e₁ = (1, 1)/√2 = (0.7071067812, 0.7071067812). v₂·e₁ = 1/√2, so u₂ = (1, 0) − ½(1, 1) = (0.5, −0.5) and e₂ = (0.7071067812, −0.7071067812).

Vectors in 4D v₁ = (1, 2, 3, 4), v₂ = (4, 3, 2, 1). v₂·v₁ = 4 + 6 + 6 + 4 = 20 and v₁·v₁ = 30, so u₂ = v₂ − (20/30)v₁ = (4 − 2/3, 3 − 4/3, 2 − 2, 1 − 8/3) = (3.333333333, 1.666666667, 0, −1.666666667).

Each vector adds one axis v₁ = (2, 0, 0), v₂ = (3, 4, 0), v₃ = (5, 6, 7). e₁ = (1, 0, 0); u₂ = (3, 4, 0) − 3e₁ = (0, 4, 0), e₂ = (0, 1, 0); u₃ = (5, 6, 7) − 5e₁ − 6e₂ = (0, 0, 7), e₃ = (0, 0, 1).

One vector v₁ = (3, 4, 0): u₁ = (3, 4, 0), |u₁| = 5, e₁ = (0.6, 0.8, 0).

Other questions people ask

What is the Gram-Schmidt process?

The Gram-Schmidt process is a method for orthonormalizing a set of vectors in an inner product space. It takes a set of linearly independent vectors and produces an orthonormal set that spans the same subspace.

What is the difference between orthogonal and orthonormal vectors?

Orthogonal vectors are perpendicular to each other (their dot product is zero), while orthonormal vectors are both orthogonal and normalized (each has unit length). The Gram-Schmidt process produces orthonormal vectors.

Why do the vectors need to be linearly independent?

Linearly independent vectors are required because the Gram-Schmidt process aims to create a basis for the subspace spanned by the original vectors. If vectors are linearly dependent, some will become zero vectors during the process, which cannot be normalized.

What are the applications of the Gram-Schmidt process?

The Gram-Schmidt process is widely used in linear algebra, quantum mechanics, signal processing, and machine learning. It's essential for creating orthonormal bases, QR decomposition, and principal component analysis.

How does the calculator handle numerical precision?

The calculator uses a tolerance of 1e-10 to handle floating-point arithmetic errors: a vector whose part outside the span of the earlier vectors is at most 1e-10 of its length counts as dependent. In the results, values within 1e-12 of zero are shown as 0.

Can I use this calculator for complex vectors?

Currently, this calculator supports only real-valued vectors. For complex vectors, you would need to separate real and imaginary parts or use specialized complex number calculators.

What happens if I enter linearly dependent vectors?

If you enter linearly dependent vectors, the calculator will detect this and show an error message naming the first vector that is a combination of the ones before it. The Gram-Schmidt process cannot be completed with linearly dependent vectors because some vectors would become zero during the process, and zero vectors cannot be normalized.

How do I verify that the result is correct?

Check that each orthonormal vector has unit length (magnitude 1), that every pair of orthonormal vectors is orthogonal (dot product 0), and that the orthonormal set spans the same subspace as the original vectors. The working shows each step.