by Marco Taboga , PhD
The trace of a square matrix is the sum of its diagonal entries.
The trace has several properties that are used to prove important results in matrix algebra and its applications.
Table of Contents
Let us start with a formal definition.
Definition Let A be a $K imes K$ matrix. Then, its trace, denoted by [eq1] or [eq2], is the sum of its diagonal entries:[画像:[eq3]]
Some examples follow.
The following subsections report some useful properties of the trace operator.
The trace of a sum of two matrices is equal to the sum of their traces.
Proposition Let A and $B$ be two $K imes K$ matrices. Then, [画像:[eq8]]
Remember that the sum of two matrices is performed by summing each element of one matrix to the corresponding element of the other matrix (see the lecture on Matrix addition). As a consequence,[画像:[eq9]]
The next proposition tells us what happens to the trace when a matrix is multiplied by a scalar.
Proposition Let A be a $K imes K$ matrix and $lpha $ a scalar. Then,[画像:[eq10]]
Remember that the multiplication of a matrix by a scalar is performed by multiplying each entry of the matrix by the given scalar (see the lecture on Multiplication of a matrix by a scalar). As a consequence,[画像:[eq11]]
The two properties above (trace of sums and scalar multiples) imply that the trace of a linear combination is equal to the linear combination of the traces.
Proposition Let A and $B$ be two $K imes K$ matrices and $lpha $ and $eta $ two scalars. Then, [画像:[eq12]]
Transposing a matrix does not change its trace.
Proposition Let A be a $K imes K$ matrix. Then,[画像:[eq13]]
The trace of a matrix is the sum of its diagonal elements, but transposition leaves the diagonal elements unchanged.
The next proposition concerns the trace of a product of matrices.
Proposition Let A be a $K imes L$ matrix and $B$ an $L imes K$ matrix. Then,[画像:[eq14]]
Note that $AB$ is a $K imes K$ matrix and $BA$ is an $L imes L$ matrix. Then,[画像:[eq15]]where in steps $ rame{A}$ and $ rame{B}$ we have used the definition of matrix product, in particular, the facts that [eq16] is equal to the dot product between the k-th row of A and the k-th column of $B$, and [eq17] is equal to the dot product between the $l$-th row of $B$ and the $l$-th column of A.
A trivial, but often useful property is that a scalar is equal to its trace because a scalar can be thought of as a 1ドル imes 1$ matrix, having a unique diagonal element, which in turn is equal to the trace.
This property is often used to write dot products as traces.
Example Let A be a 1ドル imes K$ row vector and $B$ a Kx1 column vector. Then, the product $AB$ is a scalar, and[画像:[eq18]]where in the last step we have use the previous proposition on the trace of matrix products. Thus, we have been able to write the scalar $AB$ as the trace of the $K imes K$ matrix $BA$.
Below you can find some exercises with explained solutions.
Let A be a 3ドル imes 3$ matrix defined by[画像:[eq19]]Find its trace.
By summing the diagonal elements, we obtain[画像:[eq20]]
Let A be a $K imes K$ matrix and x a Kx1 vector. Write the product[画像:[eq21]]as the trace of a product of two $K imes K$ matrices.
Since $x^{ op }Ax$ is a scalar, we have that [画像:[eq22]]Furthermore, $x^{ op }A$ is 1ドル imes K$ and x is Kx1. Therefore,[画像:[eq23]]where both $xx^{ op }$ and A are $K imes K$.
Please cite as:
Taboga, Marco (2021). "Trace of a matrix", Lectures on matrix algebra. https://www.statlect.com/matrix-algebra/trace-of-a-matrix.
Most of the learning materials found on this website are now available in a traditional textbook format.