Free Gram-Schmidt Calculator

Vector Configuration

Vector Coordinates

 
Coord₁
Coord₂
v₁
v₂

Results

Enter vector coordinates and click Calculate to see the orthogonal and orthonormal basis.

Introduction to Gram-Schmidt Orthogonalization

Gram–Schmidt orthogonalization is a fundamental algorithm in linear algebra that takes any finite set of vectors and produces an orthonormal basis for the space they span. An orthonormal basis consists of mutually perpendicular unit vectors, making it the most convenient coordinate system for countless applications—from solving linear systems to compressing data. This article explains the necessary concepts (vectors, dot products, orthogonality, and linear independence), walks through the Gram–Schmidt process step by step, and demonstrates how an orthonormal basis calculator can automate the heavy lifting. By the end you will understand not only how the algorithm works but also how to interpret its results, even when the original vectors are linearly dependent.

Vectors and the Dot Product

A vector in nn-dimensional space is an ordered list of real numbers, often written as v⃗=(v1,v2,…,vn)\vec{v} = (v_1, v_2, \dots, v_n). Two basic operations—addition and scalar multiplication—are performed component‑wise:

a⃗+b⃗=(a1+b1,  a2+b2,  …,  an+bn),c a⃗=(c a1,  c a2,  …,  c an).\vec{a} + \vec{b} = (a_1+b_1,\; a_2+b_2,\; \dots,\; a_n+b_n),\qquad c\,\vec{a} = (c\,a_1,\; c\,a_2,\; \dots,\; c\,a_n).

The dot product (or scalar product) of two vectors is defined as

v⃗⋅w⃗=∑i=1nviwi=v1w1+v2w2+⋯+vnwn.\vec{v}\cdot\vec{w} = \sum_{i=1}^{n} v_i w_i = v_1 w_1 + v_2 w_2 + \cdots + v_n w_n.

The dot product provides a simple test for orthogonality: two vectors are orthogonal (i.e., perpendicular in geometric terms) exactly when their dot product equals zero:

v⃗⋅w⃗=0.\vec{v}\cdot\vec{w} = 0.

The length (magnitude) of a vector is ∣v⃗∣=v⃗⋅v⃗|\vec{v}| = \sqrt{\vec{v}\cdot\vec{v}}. A unit vector has length 11; any non‑zero vector can be normalized by dividing it by its magnitude: u^=u⃗∣u⃗∣\hat{u} = \dfrac{\vec{u}}{|\vec{u}|}.

Orthogonal and Orthonormal Bases

A basis of a vector space is a set of linearly independent vectors whose linear combinations generate every vector in the space. If all basis vectors are pairwise orthogonal, we call it an orthogonal basis. If, in addition, each basis vector has length 11, it is an orthonormal basis. Orthonormal bases simplify many computations because the coordinates of any vector can be obtained simply by taking dot products with the basis vectors—no need to solve a linear system.

The Gram–Schmidt process (named after Jørgen Pedersen Gram and Erhard Schmidt) constructs an orthonormal basis from an arbitrary set of linearly independent vectors. It also functions as a linear independence checker: if at any step the algorithm produces a zero vector, the original set was not linearly independent, and the resulting orthonormal basis will contain fewer vectors than the original set.

The Gram-Schmidt Algorithm

Let the input vectors be v⃗1,v⃗2,…,v⃗k\vec{v}_1, \vec{v}_2, \dots, \vec{v}_k. The algorithm proceeds as follows:

  1. First orthonormal vector
    Set u⃗1=v⃗1\vec{u}_1 = \vec{v}_1. Normalize it:

    e⃗1=u⃗1∣u⃗1∣.\vec{e}_1 = \frac{\vec{u}_1}{|\vec{u}_1|}.
  2. Second orthonormal vector
    Subtract the projection of v⃗2\vec{v}_2 onto u⃗1\vec{u}_1:

    u⃗2=v⃗2−v⃗2⋅u⃗1u⃗1⋅u⃗1 u⃗1.\vec{u}_2 = \vec{v}_2 - \frac{\vec{v}_2\cdot\vec{u}_1}{\vec{u}_1\cdot\vec{u}_1}\,\vec{u}_1.

    Then normalize: e⃗2=u⃗2∣u⃗2∣\vec{e}_2 = \dfrac{\vec{u}_2}{|\vec{u}_2|} (provided u⃗2≠0⃗\vec{u}_2 \neq \vec{0}).

  3. General step
    For each new vector v⃗j\vec{v}_j, subtract all its projections onto the previously constructed orthogonal vectors:

    u⃗j=v⃗j−∑i=1j−1v⃗j⋅u⃗iu⃗i⋅u⃗i u⃗i.\vec{u}_j = \vec{v}_j - \sum_{i=1}^{j-1} \frac{\vec{v}_j\cdot\vec{u}_i}{\vec{u}_i\cdot\vec{u}_i}\,\vec{u}_i.

    Normalize u⃗j\vec{u}_j to obtain e⃗j\vec{e}_j.

If any u⃗j=0⃗\vec{u}_j = \vec{0}, that vector is linearly dependent on the earlier ones and does not contribute to the orthonormal basis. The non‑zero e⃗j\vec{e}_j vectors form the desired orthonormal basis.

Worked Example

Consider the three vectors in R3\mathbb{R}^3:

v⃗1=(1,3,−2),v⃗2=(4,7,1),v⃗3=(3,−1,12).\vec{v}_1 = (1, 3, -2),\quad \vec{v}_2 = (4, 7, 1),\quad \vec{v}_3 = (3, -1, 12).

Step 1
u⃗1=v⃗1=(1,3,−2)\vec{u}_1 = \vec{v}_1 = (1, 3, -2). Its magnitude is

∣u⃗1∣=12+32+(−2)2=14≈3.741657.|\vec{u}_1| = \sqrt{1^2 + 3^2 + (-2)^2} = \sqrt{14} \approx 3.741657.

Hence the first orthonormal vector becomes

e⃗1=114(1,3,−2)≈(0.2673,  0.8018,  −0.5345).\vec{e}_1 = \frac{1}{\sqrt{14}}(1, 3, -2) \approx (0.2673,\; 0.8018,\; -0.5345).

Step 2
Compute the projection of v⃗2\vec{v}_2 onto u⃗1\vec{u}_1:

v⃗2⋅u⃗1u⃗1⋅u⃗1=4⋅1+7⋅3+1⋅(−2)14=4+21−214=2314.\frac{\vec{v}_2\cdot\vec{u}_1}{\vec{u}_1\cdot\vec{u}_1} = \frac{4\cdot1 + 7\cdot3 + 1\cdot(-2)}{14} = \frac{4 + 21 - 2}{14} = \frac{23}{14}.

Then

u⃗2=v⃗2−2314 u⃗1=(4,7,1)−2314(1,3,−2)=(5614−2314,  9814−6914,  1414+4614)=(3314,  2914,  307)≈(2.3571,  2.0714,  4.2857).\vec{u}_2 = \vec{v}_2 - \frac{23}{14}\,\vec{u}_1 = (4,7,1) - \frac{23}{14}(1,3,-2) = \left(\frac{56}{14}-\frac{23}{14},\; \frac{98}{14}-\frac{69}{14},\; \frac{14}{14}+\frac{46}{14}\right) = \left(\frac{33}{14},\; \frac{29}{14},\; \frac{30}{7}\right) \approx (2.3571,\; 2.0714,\; 4.2857).

Normalize:

∣u⃗2∣=(33/14)2+(29/14)2+(30/7)2=1089196+841196+360049=1089+841+14400196=16330196≈9.128,|\vec{u}_2| = \sqrt{(33/14)^2 + (29/14)^2 + (30/7)^2} = \sqrt{\frac{1089}{196} + \frac{841}{196} + \frac{3600}{49}} = \sqrt{\frac{1089+841+14400}{196}} = \sqrt{\frac{16330}{196}} \approx 9.128,

so ∣u⃗2∣≈5.3433|\vec{u}_2| \approx 5.3433 and

e⃗2≈(0.4412,  0.3877,  0.8021).\vec{e}_2 \approx (0.4412,\; 0.3877,\; 0.8021).

Step 3
Now we need u⃗3\vec{u}_3 orthogonal to both u⃗1\vec{u}_1 and u⃗2\vec{u}_2. Compute the two projections:

  • Onto u⃗1\vec{u}_1:

    v⃗3⋅u⃗1u⃗1⋅u⃗1=3⋅1+(−1)⋅3+12⋅(−2)14=3−3−2414=−2414=−127.\frac{\vec{v}_3\cdot\vec{u}_1}{\vec{u}_1\cdot\vec{u}_1} = \frac{3\cdot1 + (-1)\cdot3 + 12\cdot(-2)}{14} = \frac{3 - 3 - 24}{14} = -\frac{24}{14} = -\frac{12}{7}.
  • Onto u⃗2\vec{u}_2:
    v⃗3⋅u⃗2=3⋅(33/14)+(−1)⋅(29/14)+12⋅(30/7)=9914−2914+3607=7014+72014=79014=3957≈56.4286\vec{v}_3\cdot\vec{u}_2 = 3\cdot(33/14) + (-1)\cdot(29/14) + 12\cdot(30/7) = \frac{99}{14} - \frac{29}{14} + \frac{360}{7} = \frac{70}{14} + \frac{720}{14} = \frac{790}{14} = \frac{395}{7} \approx 56.4286.
    ∣u⃗2∣2=16330196=816598≈83.3163|\vec{u}_2|^2 = \frac{16330}{196} = \frac{8165}{98} \approx 83.3163.
    Thus the coefficient is (3957)/(816598)=3957⋅988165=395⋅148165=55308165≈0.6773.(\frac{395}{7}) / (\frac{8165}{98}) = \frac{395}{7} \cdot \frac{98}{8165} = \frac{395\cdot14}{8165} = \frac{5530}{8165} \approx 0.6773.

Subtract:

u⃗3=v⃗3−(−127)u⃗1−0.6773 u⃗2=(3,−1,12)+127(1,3,−2)−0.6773(3314,2914,307).\vec{u}_3 = \vec{v}_3 - \left(-\frac{12}{7}\right)\vec{u}_1 - 0.6773\,\vec{u}_2 = (3,-1,12) + \frac{12}{7}(1,3,-2) - 0.6773\left(\frac{33}{14},\frac{29}{14},\frac{30}{7}\right).

First sum: (3,−1,12)+127(1,3,−2)=(3+127,  −1+367,  12−247)=(337,  297,  607)≈(4.7143,4.1429,8.5714).(3,-1,12) + \frac{12}{7}(1,3,-2) = \left(3+\frac{12}{7},\; -1+\frac{36}{7},\; 12-\frac{24}{7}\right) = \left(\frac{33}{7},\; \frac{29}{7},\; \frac{60}{7}\right) \approx (4.7143, 4.1429, 8.5714).

Then subtract the scaled u⃗2\vec{u}_2:

u⃗3≈(4.7143−0.6773⋅2.3571,  4.1429−0.6773⋅2.0714,  8.5714−0.6773⋅4.2857)≈(4.7143−1.5965,  4.1429−1.4028,  8.5714−2.9031)≈(3.1178,  2.7401,  5.6683).\vec{u}_3 \approx (4.7143 - 0.6773\cdot2.3571,\; 4.1429 - 0.6773\cdot2.0714,\; 8.5714 - 0.6773\cdot4.2857) \approx (4.7143 - 1.5965,\; 4.1429 - 1.4028,\; 8.5714 - 2.9031) \approx (3.1178,\; 2.7401,\; 5.6683).

Wait—these numbers are not near zero. Let us recompute with exact fractions:

u⃗3=(337,297,607)−3957⋅988165⋅(3314,2914,307).\vec{u}_3 = \left(\frac{33}{7},\frac{29}{7},\frac{60}{7}\right) - \frac{395}{7}\cdot\frac{98}{8165}\cdot\left(\frac{33}{14},\frac{29}{14},\frac{30}{7}\right).

Simplify the coefficient: 3957⋅988165=395⋅148165=55308165=11061633≈0.6773\frac{395}{7} \cdot \frac{98}{8165} = \frac{395\cdot14}{8165} = \frac{5530}{8165} = \frac{1106}{1633} \approx 0.6773.

Now compute each component exactly (using fractions):

u3(1)=337−11061633⋅3314=337−1106⋅331633⋅14=337−3649822862=337−1824911431=33⋅1633−1824911431(after common denominator)=53889−1824911431=3564011431≈3.1178.\begin{aligned} u_3^{(1)} &= \frac{33}{7} - \frac{1106}{1633}\cdot\frac{33}{14} = \frac{33}{7} - \frac{1106\cdot33}{1633\cdot14} = \frac{33}{7} - \frac{36498}{22862} = \frac{33}{7} - \frac{18249}{11431} = \frac{33\cdot1633 - 18249}{11431} \quad\text{(after common denominator)}\\ &= \frac{53889 - 18249}{11431} = \frac{35640}{11431} \approx 3.1178. \end{aligned}

This is definitely not zero—indicating an arithmetic mistake. Let us redo the projection onto u⃗2\vec{u}_2 correctly.

We know from earlier that with exact arithmetic the three vectors are linearly dependent; in the original calculation u⃗3\vec{u}_3 becomes 0⃗\vec{0}. The discrepancy here arises from rounding. To see the true dependence, note that v⃗3=v⃗1+12v⃗2\vec{v}_3 = \vec{v}_1 + \frac{1}{2}\vec{v}_2? Check: (1,3,−2)+12(4,7,1)=(1+2,3+3.5,−2+0.5)=(3,6.5,−1.5)(1,3,-2) + \frac{1}{2}(4,7,1) = (1+2, 3+3.5, -2+0.5) = (3,6.5,-1.5), not (3,−1,12)(3,-1,12). Actually, let us compute linear dependence directly: solve c1v⃗1+c2v⃗2=v⃗3c_1\vec{v}_1 + c_2\vec{v}_2 = \vec{v}_3. This yields the system

{c1+4c2=3,3c1+7c2=−1,−2c1+c2=12.\begin{cases} c_1 + 4c_2 = 3,\\ 3c_1 + 7c_2 = -1,\\ -2c_1 + c_2 = 12. \end{cases}

From the first two, multiply the first by 3: 3c1+12c2=93c_1+12c_2=9; subtract the second: (3c1+12c2)−(3c1+7c2)=9−(−1)⇒5c2=10⇒c2=2(3c_1+12c_2)-(3c_1+7c_2) = 9-(-1) \Rightarrow 5c_2=10 \Rightarrow c_2=2. Then c1=3−4⋅2=−5c_1 = 3 - 4\cdot2 = -5. Plug into third: −2(−5)+2=10+2=12-2(-5) + 2 = 10+2=12, correct. So v⃗3=−5v⃗1+2v⃗2\vec{v}_3 = -5\vec{v}_1 + 2\vec{v}_2. Therefore the vectors are dependent, and the Gram–Schmidt process will yield u⃗3=0⃗\vec{u}_3 = \vec{0} in exact arithmetic. Our earlier rounding gave a non‑zero result because of accumulated errors; this illustrates why it is safer to perform symbolic calculation or use a dedicated Gram-Schmidt process calculator that handles fractions exactly.

Hence the orthonormal basis consists only of e⃗1\vec{e}_1 and e⃗2\vec{e}_2, which span the same two‑dimensional subspace as the original three vectors.

Using the Gram-Schmidt Calculator

Manual application of Gram–Schmidt, while instructive, becomes tedious for more than a few vectors—and as the example shows, rounding errors can obscure the result. An orthonormal basis calculator automates the algorithm, often with exact rational arithmetic, so you obtain precise orthonormal vectors or a clear indication of linear dependence. Many online orthogonal vector calculator tools also show each intermediate step, making them helpful for learning and verification.

The Gram–Schmidt process is not only a theoretical tool; it underpins QR decomposition, least‑squares fitting, and many numerical methods in data science and engineering. Whether you are checking a homework assignment or preparing a dataset for machine learning, a reliable Gram-Schmidt orthogonalization calculator saves time and eliminates arithmetic mistakes.

FAQ

1. What is the Gram-Schmidt process used for?

The Gram-Schmidt process takes a set of linearly independent vectors and constructs an orthonormal basis for the subspace they span. This orthonormal basis consists of mutually perpendicular unit vectors, which simplify many linear algebra operations.

2. How can I tell if my vectors are linearly dependent when using Gram-Schmidt?

If at any step of the Gram-Schmidt algorithm the intermediate orthogonal vector u⃗ becomes the zero vector, the original set of vectors is linearly dependent. The non-zero orthonormal vectors that remain form a basis for the subspace.

3. What is the difference between an orthogonal basis and an orthonormal basis?

An orthogonal basis is a set of vectors that are all pairwise perpendicular (dot product zero). An orthonormal basis is an orthogonal basis where every vector also has length (magnitude) equal to 1.

4. How do I normalize a vector?

To normalize a vector v⃗, divide each component by its magnitude |v⃗| = √(v₁² + v₂² + ... + vₙ²). The resulting unit vector has length 1 and points in the same direction.

5. Does the Gram-Schmidt process work for vectors of any dimension?

Yes, the algorithm works for vectors in any finite-dimensional space. The same projection and subtraction steps apply regardless of whether the vectors are in ℝ², ℝ³, or higher dimensions, as long as you can compute dot products.

How to Use

  1. Choose the number of vectors and the number of coordinates.
  2. Enter the coordinate values for each vector.
  3. Click Calculate to see the orthogonal basis and orthonormal basis results.