Linear Algebra / Unit 3, Matrices / Topic 3.5
Unit 3. Matrices
This topic defines the trace of a square matrix, which is the sum of its diagonal entries. The trace is simple to calculate, and it follows rules that make it useful in the later units and in quantum mechanics.
You need Topics 3.2, 3.3, and 3.4 for this topic.
The trace of a square matrix is the sum of the entries on its main diagonal. It is written tr A.
tr abcd = a + d tr 211433879 = 2 + 3 + 9add the entries on the main diagonal= 14Only a square matrix has a trace. The trace of the n by n identity matrix is n.
The trace works with addition and with multiplication by a number in the expected way, and it does not change under the transpose.
tr(A + B) = tr A + tr B tr(cA) = c tr A tr(AT) = tr AThe first two rules say that the trace is linear. The determinant does not follow these two rules, as Topic 3.4 showed.
The most important rule is about products. The matrices AB and BA are usually different, but they always have the same trace.
tr(AB) = tr(BA)For example,
A = 1234 B = 0152 AB = 1052011 BA = 341118The two products are different matrices, but their traces are equal.
tr(AB) = 10 + 11 = 21tr(BA) = 3 + 18 = 21The reason is in the entry rule for a product. The diagonal entry of AB in row i is the sum of the products aijbji over j. So tr(AB) is the sum of aijbji over all i and all j. The trace of BA is the sum of bjiaij over all j and all i, which contains the same products.
Try it: two products, one trace
Press New matrices to choose two matrices at random. The products AB and BA are usually different, but their traces are equal.
For a product of three matrices, the rule allows the first matrix to move to the end, or the last matrix to move to the front.
tr(ABC) = tr(BCA) = tr(CAB)This is called the cyclic property of the trace. It does not allow any other change of order. In general, tr(ABC) is not equal to tr(ACB). With the matrices A and B above and C = 1102, tr(ABC) = 52 and tr(ACB) = 50.
Let P be a matrix that has an inverse. The matrices A and P⁻¹AP are called similar. Topic 4.6 shows that similar matrices describe the same map in two different sets of coordinates. The cyclic property shows that similar matrices have the same trace.
tr(P⁻¹AP) = tr(APP⁻¹) = tr AThe product rule for determinants shows that they also have the same determinant, because det(P⁻¹) det(P) = 1.
For example, take
A = 2112 P = 111−1 P⁻¹AP = 3001Both matrices have the trace 4 and the determinant 3.
The trace and the determinant belong to the map, not to the particular table of numbers that describes it. Unit 5 shows what they are in terms of the map: the trace is the sum of the eigenvalues, and the determinant is their product.
The matrix AB − BA is called the commutator of A and B. It measures how far the two matrices are from having the same product in both orders. From Part 3, the trace of a commutator is always 0.
tr(AB − BA) = tr(AB) − tr(BA)the trace is lineartr(AB − BA) = 0the two traces are equalFor the matrices of Part 3, AB − BA = 719−7, and the trace is 7 − 7 = 0.
This fact has a consequence for quantum mechanics. Position and momentum are represented by operators X and P whose commutator is a number times the identity. For n by n matrices this is impossible, because the trace of a commutator is 0 and the trace of the identity is n. So position and momentum cannot be matrices of any finite size. Unit 9 introduces the vector spaces of infinite dimension that they need.
For any matrix A, the trace of AT A is the sum of the squares of all of the entries of A.
A = 1234 AT A = 10141420 tr(AT A) = 30 = 1 + 4 + 9 + 16The square root of this number measures the size of a matrix, in the same way that √v · v measures the length of a vector. For two matrices of the same size, tr(AT B) is the sum of the products of matching entries. It is the dot product of the two matrices, treated as long lists of numbers.
The trace of a rotation matrix gives the angle of the rotation. In two dimensions, the rotation by θ from Topic 3.1 has the trace 2 cos θ. In three dimensions, a rotation by θ about any axis has the trace 1 + 2 cos θ. For a rotation about the z-axis, this can be read from the matrix.
R = cos θ−sin θ0sin θcos θ0001 tr R = 1 + 2 cos θA rotation about a different axis is similar to this matrix, so it has the same trace. To find the angle of any rotation in three dimensions, calculate cos θ = (tr R − 1) / 2.
| Fact | Statement |
|---|---|
| Definition | The sum of the entries on the main diagonal |
| Linear | tr(A + B) = tr A + tr B and tr(cA) = c tr A |
| Product | tr(AB) = tr(BA) |
| Cyclic property | tr(ABC) = tr(BCA) = tr(CAB) |
| Similar matrices | tr(P⁻¹AP) = tr A |
| Commutator | tr(AB − BA) = 0 |
| Sum of squares | tr(AT A) is the sum of the squares of the entries of A |
Work each problem on paper first. Then open the answer to check your work.
4 + 3 − 6 = 1.
AB = 4233 and BA = 2415.
tr(AB) = 4 + 3 = 7tr(BA) = 2 + 5 = 7
tr(2A − 3B) = 2 tr A − 3 tr Bthe trace is lineartr(2A − 3B) = 2(5) − 3(−2) = 16tr(AT) = 5the transpose has the same trace
The trace of AB − BA is 0 for any two square matrices. The trace of the 2 by 2 identity matrix is 2. A matrix with the trace 0 cannot be equal to a matrix with the trace 2.
1 + 2 cos θ = 2the trace of a rotation by θcos θ = (2 − 1)/2 = 1/2subtract 1, then divide by 2θ = 60°take the inverse cosine
It is the sum of the squares of the entries.
1 + 0 + 4 + 1 + 9 + 1 = 16
The instruction np.trace calculates the trace of a square matrix.
Python
The result is 14, because 2 + 3 + 9 = 14. Now change the matrix to the one in Practice Problem 1, with the rows 4, −1, 2 and 0, 3, 7 and 5, 1, −6.
Python
The code below calculates tr(AB) and tr(BA) for two 3 by 3 matrices. The @ sign multiplies two matrices.
Python
Both results are 42. Change any entries of A and B and run the code again. The two results stay equal.
In the next box, replace the zeros in the third line so that C is the commutator AB − BA. Use the @ sign for each product and the - sign between the two products.
Python
The code below prints the trace of ABC and the trace of ACB for the matrices of Part 3. The two results are different.
Python
The results are 52 and 50. In the next box, change the order of the three matrices in the last line to a different order that gives 52. Do not use the order A, B, C.
Python
The code below builds the matrix of a rotation by 60 degrees about the z-axis, and then finds the angle again from the trace. The instructions np.cos and np.sin need the angle in radians, so np.radians changes degrees to radians. The instruction np.arccos is the inverse cosine, and np.degrees changes its result back to degrees.
Python
The trace is 2, and the angle is very close to 60 degrees.
Now change the first line so that the rotation is by 135 degrees, and check that the last line finds the same angle.
Python
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. Find the trace of 5102−34782.
The trace is the sum of the entries on the main diagonal: 5 + (−3) + 2 = 4.
2. Which equation is true for all square matrices A and B of the same size?
The products AB and BA are usually different matrices, but they always have the same trace.
3. Two square matrices have tr A = 6 and tr B = −1. Find tr(A − 2B).
The trace is linear.tr(A − 2B) = tr A − 2 tr Btr(A − 2B) = 6 + 2 = 8
4. A and B are square matrices of the same size. Find the trace of the commutator AB − BA.
tr(AB − BA) = tr(AB) − tr(BA), and these two traces are equal. The trace of a commutator is always 0.
5. A rotation in three dimensions has the trace 0. Find the angle of the rotation, in degrees. Give the angle between 0° and 180°.
A rotation by θ in three dimensions has the trace 1 + 2 cos θ.1 + 2 cos θ = 0the trace is 0cos θ = −1/2subtract 1, then divide by 2θ = 120°take the inverse cosine