Scientia sine finibus

Linear Algebra / Unit 6, Orthogonality / Topic 6.2

Units and Topics

Unit 6. Orthogonality

6.2 Orthogonal Bases and the Gram-Schmidt Process

This topic studies bases whose vectors are perpendicular to each other. In such a basis, coordinates and projections are found with dot products, with no system of equations to solve. The Gram-Schmidt process builds such a basis from any basis.

You need Topics 1.4, 4.3, and 6.1 for this topic.

1. Orthogonal and Orthonormal Sets

A set of vectors is called orthogonal when each pair of different vectors in it has a dot product of 0. The set is called orthonormal when, in addition, each vector has the length 1.

qi · qj = 0 for i ≠ j and qi · qi = 1

The standard unit vectors are orthonormal. The vectors (1, 1) and (1, −1) are orthogonal, but not orthonormal, because each has the length √2. Dividing each vector by its length gives the orthonormal pair (1, 1)/√2 and (1, −1)/√2.

Orthogonal vectors, none of which is the zero vector, are always linearly independent. Take the dot product of c₁v₁ + … + ckvk = 0 with v₁. All of the terms except the first one vanish, which leaves c₁(v₁ · v₁) = 0, so c₁ = 0. The same argument works for each coefficient.

So n orthogonal vectors in a space of dimension n are a basis. It is called an orthogonal basis, or an orthonormal basis when the lengths are 1.

2. Coordinates Without Solving a System

In Topic 4.3, the coordinates of a vector in a basis came from a system of equations. In an orthogonal basis, each coordinate comes from one dot product. Write x = c₁v₁ + … + cₙvₙ and take the dot product with v₁. Only the first term survives.

ci = (vi · x)/(vi · vi) and, for an orthonormal basis, ci = qi · x

For example, find the coordinates of x = (3, 1) in the orthogonal basis (1, 1), (1, −1).

c₁ = (3 + 1)/2 = 2the dot product with the first basis vector, divided by the dot product of that basis vector with itselfc₂ = (3 − 1)/2 = 1the same for the second basis vector

These are the coordinates that Topic 4.3 found by solving two equations.

Each term civi is the projection of x onto the line of vi, from Topic 6.1. In an orthogonal basis, a vector is the sum of its projections onto the basis vectors. This is not true for a basis that is not orthogonal.

3. Projections with an Orthonormal Basis

Let q₁, …, qk be an orthonormal basis of a subspace, and let Q be the matrix with these columns. Then QT Q = I, because the entry in row i and column j of QT Q is qi · qj. The formulas of Topic 6.1 become simple, because the inverse disappears.

p = (q₁ · b)q₁ + … + (qk · b)qk P = QQT

4. The Gram-Schmidt Process

The Gram-Schmidt process starts with independent vectors a₁, a₂, a₃ and builds orthogonal vectors v₁, v₂, v₃ that span the same subspace. Each step takes the next vector and subtracts its projections onto the vectors that are already finished. What remains is perpendicular to all of them.

v₁ = a₁ v₂ = a₂ − (v₁ · a₂)/(v₁ · v₁) v₁ v₃ = a₃ − (v₁ · a₃)/(v₁ · v₁) v₁ − (v₂ · a₃)/(v₂ · v₂) v₂

At the end, divide each vector by its length to get the orthonormal vectors q₁, q₂, q₃.

Try it: one step of the Gram-Schmidt process

Drag the tips of a₁ and a₂. The dashed purple segment is the projection of a₂ onto a₁, which is subtracted. The green arrow v₂ is what remains, and it is perpendicular to a₁. The two short dark arrows are the orthonormal vectors q₁ and q₂.

An example in three dimensions

Take a₁ = (1, 1, 0), a₂ = (1, 0, 1), and a₃ = (0, 1, 1).

Step 1. v₁ = (1, 1, 0), with v₁ · v₁ = 2.

Step 2. v₁ · a₂ = 1, so

v₂ = 101 − 1/2 110subtract the projection of a₂ onto v₁v₂ = 1/2−1/21

Only the direction of v₂ matters, so multiply it by 2 to remove the fractions: v₂ = (1, −1, 2), with v₂ · v₂ = 6.

Step 3. v₁ · a₃ = 1 and v₂ · a₃ = 1, so

v₃ = 011 − 1/2 110 − 1/6 1−12subtract the projections onto v₁ and v₂v₃ = −2/32/32/3

Multiply by 3/2 to get v₃ = (−1, 1, 1).

Check:

(1, 1, 0) · (1, −1, 2) = 0(1, 1, 0) · (−1, 1, 1) = 0(1, −1, 2) · (−1, 1, 1) = 0

Dividing by the lengths √2, √6, and √3 gives the orthonormal basis.

q₁ = 1/√2 110 q₂ = 1/√6 1−12 q₃ = 1/√3 −111

5. Orthogonal Functions

The same ideas work in a vector space of functions, once a dot product of two functions is defined. For functions on an interval from a to b, the sum of the products of matching components becomes an integral.

f · g = ∫ f(x) g(x) dx, taken from a to b

Two functions are called orthogonal when this integral is 0. For example, on the interval from −1 to 1, the functions 1 and x are orthogonal, because the integral of x over that interval is 0.

  • Applying the Gram-Schmidt process to 1, x, x² on the interval from −1 to 1 gives 1, x, and x² − 1/3. These are the first of the Legendre polynomials, which appear in the quantum mechanics of the hydrogen atom.
  • The functions sin x, sin 2x, sin 3x, and so on are orthogonal on the interval from 0 to π. Writing a function as a combination of them is called a Fourier series, and each coefficient is found by one integral, exactly as each coordinate in Part 2 is found by one dot product.

In quantum mechanics, the possible states of definite energy are orthogonal functions, and a general state is a combination of them. The coefficient of each state comes from one integral. Topic 9.5 develops this.

Common Mistakes

  • Using the formula ci = qi · x with vectors that are orthogonal but do not have the length 1. Divide by vi · vi in that case.
  • Using the dot product formula for coordinates in a basis that is not orthogonal.
  • In the third step, subtracting the projection onto a₂. The projection must be onto the new vector v₂.
  • Forgetting one of the two projections in the third step.
  • Calling a set orthonormal after checking only the lengths, or only the dot products. Both conditions are needed.
  • Starting the process with dependent vectors. One of the new vectors is then the zero vector, and it must be removed.

Summary

TermMeaning
Orthogonal setEach pair of different vectors has a dot product of 0
Orthonormal setOrthogonal, and each vector has the length 1
Coordinates in an orthogonal basisci = (vi · x) / (vi · vi)
Orthonormal columnsQT Q = I
Projection with orthonormal columnsP = QQT
Gram-Schmidt processSubtract from each vector its projections onto the vectors already finished

Practice

Work each problem on paper first. Then open the answer to check your work.

1. Are (1, 2, 2), (2, 1, −2), and (2, −2, 1) orthogonal? Are they orthonormal?

2 + 2 − 4 = 02 − 4 + 2 = 04 − 2 − 2 = 0

The three dot products are 0, so the vectors are orthogonal.

Each has the length 3, so they are not orthonormal. Dividing each by 3 gives an orthonormal basis.

2. Find the coordinates of (9, 0, 0) in the orthogonal basis of Problem 1.

Each coordinate is (vi · x) / 9.

c₁ = 9/9 = 1c₂ = 18/9 = 2c₃ = 18/9 = 2(1, 2, 2) + 2(2, 1, −2) + 2(2, −2, 1) = (9, 0, 0)the check

3. Apply the Gram-Schmidt process to a₁ = (3, 4) and a₂ = (1, 2), and give the orthonormal vectors.

v₁ = (3, 4)v₁ · v₁ = 25v₁ · a₂ = 11v₂ = (1, 2) − (11/25)(3, 4) = (−0.32, 0.24)a multiple of (−4, 3)q₁ = (0.6, 0.8)v₁ divided by its length 5q₂ = (−0.8, 0.6)(−4, 3) divided by its length 5

4. Apply the Gram-Schmidt process to (1, 1, 1) and (1, 0, 2).

v₁ = (1, 1, 1)v₁ · v₁ = 3v₁ · a₂ = 3v₂ = (1, 0, 2) − (3/3)(1, 1, 1) = (0, −1, 1)subtract the projection(1, 1, 1) · (0, −1, 1) = 0the check

5. Q has the orthonormal columns (1, 0, 0) and (0, 0.6, 0.8). Find the projection of (2, 5, 0) onto the column space of Q.

The two dot products are 2 and 3.

p = 2(1, 0, 0) + 3(0, 0.6, 0.8)p = (2, 1.8, 2.4)

6. Show that the functions 1 and x² − 1/3 are orthogonal on the interval from −1 to 1.

The integral of x² − 1/3 from −1 to 1 is 2/3 − 2/3 = 0.

Python Practice

Step 1. Test whether vectors are orthogonal

The instruction np.dot calculates a dot product. The code below tests the three vectors of Practice Problem 1 in pairs.

Python

The three results are 0, so the vectors are orthogonal.

Step 2. Find coordinates with dot products

The code below finds the first coordinate of x = (9, 0, 0) in this orthogonal basis.

Python

The result is 1.0. In the next box, replace the zeros in the lines that start with c2 and c3 with the formulas for the other two coordinates. The last line rebuilds the vector from its coordinates, so it should print the vector (9, 0, 0).

Python

Step 3. Make a vector of length 1

The instruction np.linalg.norm calculates the length of a vector. Dividing a vector by its length gives a vector of length 1 in the same direction.

Python

The length of (1, 2, 2) is 3, so the result is (1/3, 2/3, 2/3), and its length is 1.

Step 4. Do the Gram-Schmidt process

The code below does the first two steps of the example in Part 4. The third line subtracts from a₂ its projection onto v₁.

Python

The result is (0.5, −0.5, 1), and it is perpendicular to v₁. Part 4 multiplied this vector by 2 to remove the fractions. Python can keep the fractions.

In the next box, replace the zeros in the line that starts with v3 with the formula of the third step. Two projections have to be subtracted from a₃: one onto v₁ and one onto v₂.

Python

Step 5. Check an orthonormal basis

The code below builds the matrix Q whose columns are the orthonormal vectors of Part 4, and calculates QTQ. The instruction np.column_stack builds a matrix from its columns, np.sqrt is the square root, and np.round rounds each entry.

Python

The result is the identity matrix. Each diagonal entry is the dot product of a column with itself, which is 1. Each other entry is the dot product of two different columns, which is 0.

Quiz

This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.

Choose how your answers are checked

1. Which pair of vectors is orthonormal?

2. The vectors (3, 4) and (−4, 3) are an orthogonal basis of the plane. Find the coefficients c₁ and c₂ in (10, 5) = c₁(3, 4) + c₂(−4, 3).

3. Apply the Gram-Schmidt process to a₁ = (1, 1) and a₂ = (4, 0). Find v₂.

4. Apply the Gram-Schmidt process to a₁ = (1, 0, 1) and a₂ = (3, 1, 1). Find v₂.

5. The matrix Q has orthonormal columns. Which equation is always true?

Next: Topic 6.3, Orthogonal Matrices and QR Factorization