# What is the Gram-Schmidt basis?

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.

- Page: https://www.acalculator.org/math/gram-schmidt-calculator
- JSON spec: https://www.acalculator.org/math/gram-schmidt-calculator.json
- Version: 81653ef80ba1

## Default answer

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].

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| v | Vectors (one per row) | The vectors v₁, v₂, …, one per row: 1 to 10 vectors of dimension 1 to 10. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| basis | Orthonormal basis | The unit vectors e₁, e₂, … as rows separated by semicolons, rounded to 10 significant figures. |
| u1 | u1 | Orthogonal vector 1: v1 minus its projections onto the earlier unit vectors. |
| u2 | u2 | Orthogonal vector 2: v2 minus its projections onto the earlier unit vectors. |
| u3 | u3 | Orthogonal vector 3: v3 minus its projections onto the earlier unit vectors. |
| u4 | u4 | Orthogonal vector 4: v4 minus its projections onto the earlier unit vectors. |
| u5 | u5 | Orthogonal vector 5: v5 minus its projections onto the earlier unit vectors. |
| u6 | u6 | Orthogonal vector 6: v6 minus its projections onto the earlier unit vectors. |
| u7 | u7 | Orthogonal vector 7: v7 minus its projections onto the earlier unit vectors. |
| u8 | u8 | Orthogonal vector 8: v8 minus its projections onto the earlier unit vectors. |
| u9 | u9 | Orthogonal vector 9: v9 minus its projections onto the earlier unit vectors. |
| u10 | u10 | Orthogonal vector 10: v10 minus its projections onto the earlier unit vectors. |
| steps | Working | Each uᵢ as vᵢ minus its projections, then eᵢ = uᵢ ÷ \|uᵢ\|. |

## Method

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

## Assumptions

- 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.

## Worked examples

1. v = 0 or 3 or 1 or 0 gives 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. v = 1 or 1 or 1 or 0 gives 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. v = 1 or 2 or 4 or 3 gives u2 = [3.333333333, 1.666666667, 0, -1.666666667], 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. v = 2 or 0 or 3 or 4 gives 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. v = 3 or 4 or undefined gives 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/.

## FAQ

### 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.

## Sources

- 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/
