Lecture 17 · Orthogonal matrices and Gram-Schmidt orthogonalization
Use Gram-Schmidt to turn a set of basis into an orthonormal basis and understand QR decomposition.
On this page
Orthogonal matrices and Gram-Schmidt | Gilbert Strang | MIT 18.06 Linear Algebra
Lecture 17 / Total 35 Lectures |Part 2 · Orthogonality and Determinant
Video of this lecture: Bilibili p17 · Orthogonal matrices and Gram-Schmidt orthogonalization ↗(49:25)| MIT OCW official page ↗
Illustration: MIT OCW 18.06SC official lecture summary (CC BY-NC-SA 4.0) and Bilibili classroom video frames (time stamped), about 10 frames per lecture.
Introduction to this lecture
The chapter on orthogonality concludes this lecture. We have dealt with two kinds of “orthogonality” before: two vectors inner product (inner product) is zero, and one subspace is perpendicular to another subspace everywhere (the row space and the null space are a pair). This lecture generalizes orthogonality from “two” to “a set”: If each vector in a set of bases is perpendicular to all other vectors, and each vector is reduced to length The unit vector of , this group of basis is called orthonormal basis (orthonormal basis). Arrange orthonormal vectors in columns into a matrix , you will get the cleanest equation in this chapter: .
This lecture is divided into two halves. The first half explains why this equation is worth pursuing. projection matrix (projection matrix) was originally , requires inversion; change to standard orthogonal After that, the middle That’s it , the projection matrix immediately degenerates into .least squares The core equation of (least squares) Similarly degenerated, the left side becomes the identity matrix, and the solution is directly ——Each component is just an inner product, and no inversion is required. This is also why numerical linear algebra is largely organized around orthonormal vectors: the lengths are nailed to , the component will not get larger or smaller, nor will it overflow or underflow.
The second half solves “What to do if you don’t have an orthonormal basis in hand”. Given a set of linearly independent (linearly independent) vectors with arbitrary directions, Gram-Schmidt (Gram-Schmidt) Orthogonalization is corrected direction by direction: retain the first direction, subtract the component of the second vector along the first direction, then subtract the components of the third vector along the first two directions, and finally divide each vector by its own length. The whole process is written as a matrix : The columns of are orthogonal, is upper triangular matrix (upper triangular matrix). This is the same as the elimination derivation At the same level - elimination makes the matrix into a triangle, and Gram-Schmidt makes the matrix into “an orthonormal column matrix multiplied by a triangular matrix”.

MIT OCW Official Lecture Notes Summary Page 1/3 (18.06SC Lecture 17 Summary, CC BY-NC-SA 4.0).
1. Standard orthogonal vector group and
The question to be answered in this section is: How to use a matrix equation to summarize “a set of vectors that are perpendicular to each other and have unit length”.
Let the vector group . It is customary to use letters Represents this family of vectors because it suggests that these vectors are orthogonal in pairs, rather than a bunch of vectors picked at random. Standard orthogonality contains two requirements, corresponding to two conditions:
The first one is orthogonal (orthogonal): The inner product of any two different vectors is zero and their directions are ninety degrees to each other. The second item is the unit length: . A vector is of course not orthogonal to itself, so the diagonal position must be specified separately as ; “Orthogonal” plus “unitized” are collectively called orthogonal (orthonormal). A basis that only satisfies the first condition is called an orthonormal basis, and a basis that satisfies both of the two is called a standard orthonormal basis; this lecture uses the latter.
put this vectors are put into the matrix one by one of columns. It doesn’t have to be a square matrix - for example, two orthogonal vectors placed in a four-dimensional space, That’s it of. Calculate now : of the OK , of the Column is , so the product of element is . The above two conditions determine each position: on the diagonal is , the remaining positions are . So
This is a “row times column” multiplication: All the inner products were asked at once, and the standard positive answer was the best of all possible answers——identity matrix (identity matrix). Think back to the recurring theme in this chapter , which records exactly all the inner products between each column; It shows that when the columns are orthogonal, this inner product table degenerates into its simplest form.
if It is a square matrix, and the conclusion is stronger: Description That’s it The inverse of . At this time, left multiplication and right multiplication are equal to , is also established. Note that this last one only applies to square array is established; the rectangular matrix only has , while No .
There is an asymmetry in terminology worth noting: When the columns of are orthogonal, the most appropriate name should be “orthogonal matrix”, but the agreement only refers to square array called orthogonal matrix (orthogonal matrix), the rectangular matrix only says “has standard orthogonal columns”. There is no mathematical reason for this habit. Just remember the conclusion: an orthogonal matrix must be a square matrix, and .
There is also a basic fact: orthonormal vectors must be linearly independent. If a certain combination , use it with Do inner product, divide Everything except that term disappears due to orthogonality, leaving only . Every coefficient must be zero, and the set of vectors is irrelevant. So “orthogonal” is stronger than “irrelevant”: it guarantees independence, and additionally controls the length and angle.

Video 00:04:56|Approximately corresponding to Section 1 “1. Standard orthogonal vector group and “Nearby.

Video 00:09:17|Approximately corresponding to Section 1 “1. Standard orthogonal vector group and “Nearby.
2. Several examples that must be remembered
The purpose of this section is to use specific matrices to implement the definition in the previous section, and at the same time accumulate models that will be used repeatedly later.
The simplest source is permutation matrix (permutation matrix): only one per row and column , the rest are all zero. For example
Its three columns are , are all unit vectors and the inner product of each pair is zero, so they are orthogonal matrices. Its transpose is another permutation matrix and therefore also orthonormal. Use one column Of course it is too easy to create a standard orthogonal column, but it illustrates an important point: standard orthogonality only requires direction and length, and does not require the vector to be “complex”.
The second source is “a unit vector plus its vertical direction” in the plane. Any angle ,
first column satisfy , is the unit vector; the second column Likewise. The inner product of two columns is , so they are perpendicular to each other. put Substitute it in and make some sign adjustments, and you get the simplest non-trivial example:
Its two columns are indeed perpendicular, but the square length of each column is , the length is , so it is not an orthogonal matrix yet. The correction is simply to divide the whole by :
This sequence of “first laying out the vertical direction, and finally dividing it by the length” is exactly the general structure of Gramm-Schmidt later.
The third source contains only matrix, called Hadamard matrix. The fourth-order example is to repeat the pattern of the previous second-order matrix and then negative one of the entire blocks:
Randomly check several pairs of columns: the inner product of the first column and the second column is ;The first and third columns are ;The second and third columns are . Each column has four , the length squared is , divided by Then the length is exactly . All these elements are the orthogonal matrix, level, level, level, Hierarchical situations people know how to construct; Orders cannot exist; there are still some orders that no one knows whether they exist.
The fourth source is the orthonormal column of rectangles, which is the shape that projection and least squares really encounter. Take two vectors in three-dimensional space
Their inner product is , the square of each length is , the length is . Therefore
is a The matrix of , its two columns are the orthonormal basis of a certain two-dimensional subspace. To make it up For an orthogonal matrix, you can add another column following this symbolic pattern: take the third column , its inner product with the first two columns is respectively and , the length squared is . So
is an orthogonal matrix, all elements are simply divided by , not a single square root appears. This kind of good luck is not common: when doing Gram-Schmidt, dividing by the length always brings up the square root.

Video 00:18:47 | Approximately corresponding to section 2 “2. Several examples that must be remembered”.
3. Benefits brought by standard orthogonality: projection and least squares
This section answers the motivational question: What exactly do you get in exchange for the effort to create an orthonormal basis. The answer is that the formulas in this chapter also become simpler.
Let’s look at the projection first. to vector Project to of column space (column space), the general formula given in the previous lectures is
when When the columns of , the one in the middle completely disappears, leaving
There is no need to calculate any inverse, and the product is just a combination of “column times row”. Let’s easily verify the two properties that the projection matrix must satisfy. The first one is symmetry: , transpose swaps the positions of two factors and transposes each, and finally returns to the original state. The second one is “projecting twice equals projecting once”:
In the middle step, put the two between Replace with It is eliminated, and the basis is exactly “column standard orthogonality”.
The two extremes must be distinguished. if is a square matrix, its column space is the entire space, and the projection should not move any vector. At this time , which is the same as the “square matrix “Consistent. if It’s rectangular, No : It is a matrix that acts on the entire space, pressing the vector to of In dimensional space, vectors generally change.
Let’s look at least squares again. The core equations in the previous lectures are normal equation(normal equation)
put Replace with , the equation becomes , the left side is the identity matrix, so
No. The coefficient is the basis vectors and The inner product of. The original method requires first calculating all the inner accumulations to form , solve another system of equations; now there is no system of equations to solve, no matrix requiring inversion, just calculate a dot product for each component separately. This is the most valuable formula of the standard orthonormal basis: under the standard orthonormal basis, the coordinates are projections, which are inner products, and do not require “solution”.
The numerical benefit is here too. The length of an orthonormal vector is always , no matter how messy the direction is, it will not make the components become extremely large or extremely small, and there will be neither overflow nor underflow in the calculation; this is why a large number of numerical linear algebra uses standard orthogonal vectors as the basic building blocks.

MIT OCW Official Lecture Notes Summary Page 2/3 (18.06SC Lecture 17 Summary, CC BY-NC-SA 4.0).

Video 00:25:31 | Approximately corresponding to Section 3 “3. Benefits of orthogonality: projection and least squares”.
4. Gramm-Schmidt: case of two vectors
The remaining problem is construction: How to get the orthonormal vectors when we only have a set of vectors that are linearly independent but have random directions?
First deal with two vectors. Set Linear independence, to create . The process is divided into two steps: first turn them into two mutually perpendicular vectors, and then divide each by their length. To avoid having to deal with the matrix Confused, this paragraph marks the vector after orthogonalization but not unitized as .
There is almost no need to do this first step. There is no problem with the direction itself. Any direction can be used as the first direction. Just take
The trouble is with the second vector: Generally not perpendicular to . What you are looking for is “from Set off, just take the edge “Remove that part of the direction”. This is the earliest basic calculation in this chapter: put Project to on, the projection is along That part, minus it, the remainder is the vertical part, which is the error vector at that time . What we want now is this error vector:
The coefficient is the ratio of “how many times to reduce”: the numerator is in The inner product in the direction, the denominator is and its own inner product, divide the two to align the units, so that what is subtracted is exactly a multiple of the projection, not the Lose the whole thing. Orthogonalization and unitization are two independent things: orthogonalization only uses inner products and multiples, which is the essence of the algorithm; unitization is just the final division of the length.
Whether this structure is correct or not can be seen by multiplying it:
If you subtract the same numbers in the numerator and denominator, the result is indeed zero. Nor will it be a zero vector: if , then is A multiple of , the two vectors are linearly related, which is inconsistent with the assumption. So these two vectors still form the original two-dimensional subspace, but the directions are corrected.
The final step is normalization, where the square root appears:
Dividing by a positive number does not change the direction, only changes the length to ; Two vectors are originally perpendicular, but remain perpendicular after dividing by a positive number. The algorithm ends here: orthonormal and with into the same subspace.

Video 00:32:07 | Approximately corresponding to Section 4 “4. Gramm-Schmidt: The case of two vectors”.
5. Three vectors and one numerical example
The situation of the three vectors is exactly the same. Set Linearly independent, the first two have been processed into , the third one should start from subtract all its components in the first two directions:
The two items are divided into , along components are reduced. due to are already perpendicular to each other. These two subtractions do not interfere with each other. After the subtraction, Perpendicular to both. It will not be a zero vector because linear independence guarantees Not in the plane spanned by the first two vectors. Finally divided by the length, we get . The whole method has nothing to do with dimensionality: the vector can be in a two-dimensional plane or in a twelve-dimensional space, and the formula only uses the inner product and length. Generally, no. vector to be subtracted from the front all components in known directions, and each later obtained are perpendicular to all earlier vectors - this property is what the next section Become the source of the upper triangle.
Go through it with a specific example. take
The two vectors are not perpendicular: the inner product is , just needs orthogonalization.
Copy the first direction: . Calculate the ratio:
thus
Check orthogonality: , indeed vertical. The proportion is exactly It is a coincidence of numbers, generally not integers.
Finally unitized. , , so
Arrange them in a matrix
Its two columns are orthogonal and can be directly checked : On the diagonal is with , the off-diagonal line is .
The most critical point in this example is Column space has not changed. The column space and original reason of The planes formed are the same plane: It is originally a combination of the two, and unitization just replaces the columns with another set of basis in the same plane. What Gram-Schmidt changed was only the mass of the basis, but not the space spanned by the basis. So any calculations on the original plane - projection, least squares, coordinates - can be done on the new basis, and the new basis makes every step a dot product.

Video 00:38:32 | Approximately corresponding to Section 5 “5. Three vectors and a numerical example”.
6. Matrix language:
Orthogonalization also needs to be written as a matrix factorization, just like elimination is finally written as . In practice, no one would always write “these columns are perpendicular to each other and the length of these columns is ”, people wrote with the matrix between.
Let’s sort out the examples from the previous section. The columns are , The columns are . The two sets of columns are stretched into the same plane, and each can be written combination of , then there exists a matrix such that
This can be calculated column by column. with In the same direction, the length is , so ; Write it first , and then use express, get . Together it is
The upper triangle shape is no coincidence. Generally, if The columns of are orthogonal, The columns are , then of the column gives . Take left on both sides , due to The columns of are orthogonal in pairs, leaving only One item:
Now let’s see why everything below the diagonal is zero. When when, fall on in the Zhang Cheng space, and was created later, and is constructed perpendicular to all earlier directions according to the algorithm, so , that is . This is exactly the definition of an upper triangular matrix: all zeros below the main diagonal. The diagonal element is , in the example with .
So we get the final conclusion of this lecture: any linearly independent matrix can be decomposed into the product of an orthogonal column matrix and an upper triangular matrix. This decomposition is called QR decomposition(QR factorization):
gives the orthonormal basis of the same column space, Record the coefficients required for the new basis to represent the old column; Each number in is the inner product and length that have been calculated during the orthogonalization process, and no new quantities are introduced. Got it , the projection is , the least squares solution is , all no longer need to be inverse; with , only then do we know how to convert this set of beautiful bases to the original matrix. This is exactly how elimination and orthogonalization work: Store the elimination information into the lower triangular matrix, Store the orthogonalized information into an upper triangular matrix.

Video 00:44:28|Approximately corresponding to Section 6 “6. Matrix Language: “Nearby.

MIT OCW Official Lecture Notes Summary Page 3/3 (18.06SC Lecture 17 Summary, CC BY-NC-SA 4.0).
Summary of this lecture
- orthogonal (orthonormal) means that the inner product of each pair is zero, and the length of each vector is ;The condition is written as , that is, the diagonal angle is , the rest are .
- If The columns of are orthogonal, then ;if Or square array, then , that is . It was agreed to only call the square array orthogonal matrix(orthogonal matrix).
- Orthogonal vectors must be linearly independent: use Go to the dot multiplication zero combination to force out the first coefficient is zero.
- Typical example: permutation matrix; the two columns are with matrix; of Divide the entire matrix by ;The entire fourth-order Hadamard matrix is divided by ;The example with three rows and two columns divides the whole by .
- When the columns are orthogonal, the projection matrix degenerates into , it is symmetrical and satisfies ; When it is a square matrix .
- The normal equation degenerates into , that is , No. The coefficient is : “Coordinates are dot products”.
- Two core steps of Gramm-Schmidt: orthogonalization , , when there are three vectors, subtract the edge component; then unitize .
- Numerical example: , given ;The two columns after unitization are with , the column space is still the original plane.
- The whole process is written as , is an upper triangular matrix; It’s because it’s later perpendicular to earlier .
keywords
| English | Chinese | One sentence explanation |
|---|---|---|
| orthonormal | orthogonal | The inner product of each pair is zero and the length of each vector is |
| orthonormal basis | orthonormal basis | A basis consisting of orthonormal vectors, the coordinates can be read directly from the inner product |
| orthogonal matrix | orthogonal matrix | A standard orthogonal square matrix satisfies |
| Gram-Schmidt | Gram-Schmidt | Orthogonalization algorithm that subtracts the projection in the obtained direction one by one from the linearly independent vector group and then normalizes it |
| QR factorization | QR decomposition | Write a matrix whose columns are linearly independent as the product of an orthogonal column matrix and an upper triangular matrix |
| projection matrix | projection matrix | Project the vector into a matrix in the column space. When the columns are orthogonal, it simplifies to |
| normal equation | normal equation | least squares equation , The situation degenerates into |
| permutation matrix | permutation matrix | Only one per row and column The square matrix of is always an orthogonal matrix |
| Hadamard matrix | Hadamard matrix | All elements are Orthogonal matrix of , the fourth-order example requires dividing the whole by |
| upper triangular matrix | upper triangular matrix | A matrix with all zeros below the main diagonal, in That’s this kind of thing |
Machine-assisted translation · Read Chinese original
