Section MO Matrix Operations
In this section we will back up and start simple. We begin with a definition of a totally general set of matrices, and see where that takes us.
Subsection MEASM Matrix Equality, Addition, Scalar Multiplication
Definition VSM. Vector Space of
Just as we made, and used, a careful definition of equality for column vectors, so too, we have precise definitions for matrices.
Definition ME. Matrix Equality.
So equality of matrices translates to the equality of complex numbers, on an entry-by-entry basis. Notice that we now have yet another definition that uses the symbol “=” for shorthand. Whenever a theorem has a conclusion saying two matrices are equal (think about your objects), we will consider appealing to this definition as a way of formulating the top-level structure of the proof.
We will now define two operations on the set Again, we will overload a symbol (‘+’) and a convention (juxtaposition for scalar multiplication).
Definition MA. Matrix Addition.
So matrix addition takes two matrices of the same size and combines them (in a natural way!) to create a new matrix of the same size. Perhaps this is the “obvious” thing to do, but it does not relieve us from the obligation to state it carefully.
Example MA. Addition of two matrices in .
If
then
Our second operation takes two objects of different types, specifically a number and a matrix, and combines them to create another matrix. As with vectors, in this context we call a number a scalar in order to emphasize that it is not a matrix.
Definition MSM. Matrix Scalar Multiplication.
Notice again that we have yet another kind of multiplication, and it is again written putting two symbols side-by-side. Computationally, scalar matrix multiplication is very easy.
Example MSM. Scalar multiplication in .
For the scalar and the matrix
Sage MS. Matrix Spaces.
Sage defines our set as a “matrix space” with the command from just a list of 6 entries, by coercing the list into a matrix by using the relevant matrix space as if it were a function. Then we can perform the basic operations of matrix addition (Definition MA) and matrix scalar multiplication (Definition MSM).
MatrixSpace(R, m, n)
where R
is a number system and m
and n
are the number of rows and number of columns, respectively. This object does not have much functionality defined in Sage. Its main purposes are to provide a parent for matrices, and to provide another way to create matrices. The two matrix operations just defined (addition and scalar multiplication) are implemented as you would expect. In the example below, we create two matrices in xxxxxxxxxx
MS = MatrixSpace(QQ, 2, 3)
MS
xxxxxxxxxx
A = MS([1, 2, 1, 4, 5, 4])
B = MS([1/1, 1/2, 1/3, 1/4, 1/5, 1/6])
A + B
xxxxxxxxxx
60*B
xxxxxxxxxx
5*A - 120*B
Coercion can make some interesting conveniences possible. Notice how the scalar times an identity matrix of the proper size.
37
in the following expression is coerced to xxxxxxxxxx
A = matrix(QQ, [[ 0, 2, 4],
[ 6, 0, 8],
[10, 12, 0]])
A + 37
This coercion only applies to sums with square matrices. You might try this again, but with a rectangular matrix, just to see what the error message says.
Subsection VSP Vector Space Properties
With definitions of matrix addition and scalar multiplication we can now state, and prove, several properties of each operation, and some properties that involve their interplay. We now collect ten of them here for later reference.
Theorem VSPM. Vector Space Properties of Matrices.
Suppose that is the set of all matrices (Definition VSM) with addition and scalar multiplication as defined in Definition MA and Definition MSM. Then
- ACM Additive Closure, Matrices
- SCM Scalar Closure, Matrices
- CM Commutativity, Matrices
- AAM Additive Associativity, Matrices
- ZM Zero Matrix, Matrices
- AIM Additive Inverses, Matrices
- SMAM Scalar Multiplication Associativity, Matrices
- DMAM Distributivity across Matrix Addition, Matrices
- DSAM Distributivity across Scalar Addition, Matrices
- OM One, Matrices
Proof.
While some of these properties seem very obvious, they all require proof. However, the proofs are not very interesting, and border on tedious. We will prove one version of distributivity very carefully, and you can test your proof-building skills on some of the others. We will give our new notation for matrix entries a workout here. Compare the style of the proofs here with those given for vectors in Theorem VSPCV — while the objects here are more complicated, our notation makes the proofs cleaner.
To prove Property DSAM, we need to establish the equality of two matrices (see Proof Technique GS). Definition ME says we need to establish the equality of their entries, one-by-one. How do we do this, when we do not even know how many entries the two matrices might have? This is where the notation for matrix entries, given in Definition M, comes into play. Ready? Here we go.
For any and
There are several things to notice here. (1) Each equals sign is an equality of scalars (numbers). (2) The two ends of the equation, being true for any and allow us to conclude the equality of the matrices by Definition ME. (3) There are several plus signs, and several instances of juxtaposition. Identify each one, and state exactly what operation is being represented by each.
For now, note the similarities between Theorem VSPM about matrices and Theorem VSPCV about vectors.
The zero matrix described in this theorem, is what you would expect — a matrix full of zeros.
Definition ZM. Zero Matrix.
Subsection TSM Transposes and Symmetric Matrices
We describe one more common operation we can perform on matrices. Informally, to transpose a matrix is to build a new matrix by swapping its rows and columns.
Definition TM. Transpose of a Matrix.
Example TM. Transpose of a matrix.
We could formulate the transpose, entry-by-entry, using the definition. But it is easier to just systematically rewrite rows as columns (or vice-versa). The form of the definition given will be more useful in proofs. So for the matrix we have
It will sometimes happen that a matrix is equal to its transpose. In this case, we will call a matrix symmetric. These matrices occur naturally in certain situations, and also have some nice properties, so it is worth stating the definition carefully. Informally a matrix is symmetric if we can “flip” it about the main diagonal (upper-left corner, running down to the lower-right corner) and have it look unchanged.
Definition SYM. Symmetric Matrix.
Example SYM. A symmetric matrix.
The matrix below is symmetric.
You might have noticed that Definition SYM did not specify the size of the matrix as has been our custom. That is because it was not necessary. An alternative would have been to state the definition just for square matrices, but this is the substance of the next proof.
Before reading the next proof, we want to offer you some advice about how to become more proficient at constructing proofs. Perhaps you can apply this advice to the next theorem. Have a peek at Proof Technique P now.
Theorem SMS. Symmetric Matrices are Square.
Proof.
We start by specifying ’s size, without assuming it is square, since we are trying to prove that, so we cannot also assume it. Suppose is an matrix. Because is symmetric, we know by Definition SYM that So, in particular, Definition ME requires that and must have the same size. The size of is Because has rows and has rows, we conclude that and hence must be square by Definition SQM.
We finish this section with three easy theorems, but they illustrate the interplay of our three new operations, our new notation, and the techniques used to prove matrix equalities.
Theorem TMA. Transpose and Matrix Addition.
Proof.
The statement to be proved is an equality of matrices, so we work entry-by-entry and use Definition ME. Think carefully about the objects involved here, and the many uses of the plus sign. Realize too that while and are matrices, the conclusion is a statement about the equality of two matrices! So we begin with a preparation for Definition ME. For
Theorem TMSM. Transpose and Matrix Scalar Multiplication.
Proof.
The statement to be proved is an equality of matrices, so we work entry-by-entry and use Definition ME. Notice that the desired equality is of matrices, and think carefully about the objects involved here, plus the many uses of juxtaposition. For
Theorem TT. Transpose of a Transpose.
Proof.
We again want to prove an equality of matrices, so we work entry-by-entry and use Definition ME. For
Subsection TM Triangular Matrices
An upper, or lower, triangular matrix is exactly what it sounds like it should be, but here are the two relevant definitions.
Definition UTM. Upper Triangular Matrix.
Definition LTM. Lower Triangular Matrix.
So an upper triangular matrix has all its entries “below” the diagonal equal to zero, and a lower triangular matrix has all its entries “above” the diagonal equal to zero.
Example ULTM. Upper and lower triangular matrices.
The matrix is upper triangular, while is lower triangular.
As a square matrix, we can ask when a triangular matrix is nonsingular (Definition NM). Turns out we can tell just by looking.
Theorem NTM. Nonsingular Triangular Matrices.
Suppose that is a triangular matrix. Then is nonsingular if and only if every diagonal entry is nonzero.
Proof.
We give a proof for an upper triangular matrix, since it is marginally simpler, so suppose is an upper triangular matrix of size
(⇐)
For each column, its entry on the diagonal is nonzero, so we can form its reciprocal (Property MICN) and use this as the multiple for a row operation of the second type (Definition RO) to form a row-equivalent matrix that replaces the entry by a The entry, along with repeated row operations of the third type, will form a row-equivalent matrix where the column is a pivot column. So the matrix is row-equivalent to a square matrix where every column is a pivot column; in other words, the identity matrix (Definition IM). By Theorem NMRRI we see that is nonsingular.
(⇒)
We will establish the contrapositive (Proof Technique CP): if there is a zero diagonal entry then the matrix is singular. Suppose that the entry in row and column is zero. Then the first columns of are each vectors with arbitrary entries, followed by zeros. These column vectors are a linearly independent set, which can be established with a nontrivial relation of linear dependence obtained by an argument entirely similar to the proof of Theorem MVSLD. The one change is that the relevant coefficient matrix would be a matrix formed from the first columns and first rows of With linearly dependent columns, Theorem NMLIC says is singular.
Example NSTM. Nonsingular and singular triangular matrices.
We can now see immediately with Theorem NTM that the matrix of Example ULTM is singular, and the matrix of Example ULTM is nonsingular. Indeed, these two matrices could be very helpful as you study the proof of Theorem NTM.
Subsection MCC Matrices and Complex Conjugation
As we did with vectors (Definition CCCV), we can define what it means to take the conjugate of a matrix.
Definition CCM. Complex Conjugate of a Matrix.
Example CCM. Complex conjugate of a matrix.
For the matrix we compute the conjugate of
The interplay between the conjugate of a matrix and the two operations on matrices is what you might expect.
Theorem CRMA. Conjugation Respects Matrix Addition.
Proof.
For
Theorem CRMSM. Conjugation Respects Matrix Scalar Multiplication.
Proof.
For
Theorem CCM. Conjugate of the Conjugate of a Matrix.
Proof.
For
Finally, we will need the following result about matrix conjugation and transposes later.
Theorem MCT. Matrix Conjugation and Transposes.
Proof.
For
Subsection AM Adjoint of a Matrix
The combination of transposing and conjugating a matrix will be important in subsequent sections, such as Subsection MINM.UM and Section OD. We make a key definition here and prove some basic results in the same spirit as those above.
Definition A. Adjoint.
You will see the adjoint written elsewhere variously as or Notice that Theorem MCT says it does not really matter if we conjugate and then transpose, or transpose and then conjugate.
Theorem AMA. Adjoint and Matrix Addition.
Proof.
Theorem AMSM. Adjoint and Matrix Scalar Multiplication.
Proof.
Theorem AA. Adjoint of an Adjoint.
Proof.
Take note of how the theorems in this section, while simple, build on earlier theorems and definitions and never descend to the level of entry-by-entry proofs based on Definition ME. In other words, the equal signs that appear in the previous proofs are equalities of matrices, not scalars (which is the opposite of a proof like that of Theorem TMA).
Sage MO. Matrix Operations.
Every operation in this section is implemented in Sage. The only real subtlety is determining if certain matrices are symmetric, which we will discuss below. In linear algebra, the term “adjoint” has two unrelated meanings, so you need to be careful when you see this term. In particular, in Sage it is used to mean something different. So our version of the adjoint is implemented as the matrix method
.conjugate_transpose()
. Here are some straightforward examples.xxxxxxxxxx
A = matrix(QQ, [[-1, 2, 4],
[ 0, 3, 1]])
A
xxxxxxxxxx
A.transpose()
xxxxxxxxxx
A.is_symmetric()
xxxxxxxxxx
B = matrix(QQ, [[ 1, 2, -1],
[ 2, 3, 4],
[-1, 4, -6]])
B.is_symmetric()
xxxxxxxxxx
C = matrix(QQbar, [[ 2-I, 3+4*I],
[5+2*I, 6]])
C.conjugate()
xxxxxxxxxx
C.conjugate_transpose()
With these constructions, we can test, or demonstrate, some of the theorems above. Of course, this does not make the theorems true, but is satisfying nonetheless. This can be an effective technique when you are learning new Sage commands or new linear algebra — if your computations are not consistent with theorems, then your understanding of the linear algebra may be flawed, or your understanding of Sage may be flawed, or Sage may have a bug! Note in the following how we use comparison (
==
) between matrices as the implementation of matrix equality (Definition ME).xxxxxxxxxx
A = matrix(QQ, [[ 1, -1, 3],
[-3, 2, 0]])
B = matrix(QQ, [[5, -2, 7],
[1, 3, -2]])
C = matrix(QQbar, [[2+3*I, 1 - 6*I], [3, 5+2*I]])
A.transpose().transpose() == A
xxxxxxxxxx
(A+B).transpose() == A.transpose() + B.transpose()
xxxxxxxxxx
(2*C).conjugate() == 2*C.conjugate()
xxxxxxxxxx
a = QQbar(3 + 4*I)
acon = a.conjugate()
(a*C).conjugate_transpose() == acon*C.conjugate_transpose()
The opposite is true — you can use theorems to convert, or express, Sage code into alternative, but mathematically equivalent forms.
Here is the subtlety. With approximate numbers, such as in
RDF
and CDF
, it can be tricky to decide if two numbers are equal, or if a very small number is zero or not. In these situations Sage allows us to specify a “tolerance” — the largest number that can be effectively considered zero. Consider the following:xxxxxxxxxx
A = matrix(CDF, [[1.0, 0.0], [0.0, 1.0]])
A
xxxxxxxxxx
A.is_symmetric()
xxxxxxxxxx
A[0,1] = 0.000000000002
A
xxxxxxxxxx
A.is_symmetric()
xxxxxxxxxx
A[0,1] = 0.000000000001
A
xxxxxxxxxx
A.is_symmetric()
Clearly the last result is not correct. This is because is “small enough” to be confused as equal to the zero in the other corner of the matrix. However, Sage will let us set our own idea of when two numbers are equal, by setting a tolerance on the difference between two numbers that will allow them to be considered equal. The default tolerance is set at Here we use Sage’s syntax for scientific notation to specify the tolerance.
xxxxxxxxxx
A = matrix(CDF, [[1.0, 0.0], [0.0, 1.0]])
A.is_symmetric()
xxxxxxxxxx
A[0,1] = 0.000000000001
A.is_symmetric()
xxxxxxxxxx
A.is_symmetric(tol=1.0e-13)
This is not a course in numerical linear algebra, even if that is a fascinating field of study. To concentrate on the main ideas of introductory linear algebra, whenever possible we will concentrate on number systems like the rational numbers or algebraic numbers where we can rely on exact results. If you are ever unsure if a number system is exact or not, just ask.
xxxxxxxxxx
QQ.is_exact()
xxxxxxxxxx
RDF.is_exact()
Reading Questions MO Reading Questions
1. Calculate sum and scalar mult of matrices.
2. Vector space of matrices.
Theorem VSPM reminds you of what previous theorem? How strong is the similarity?
3. Calculate transpose.
Exercises MO Exercises
C10.
Solution.
is undefined; and are not the same size. is undefined; and are not the same size.
C11.
Solution.
The given equation
is valid only if Thus, the only solution is
C12.
Solution.
The given equation
leads to the 6 equations in
The only value that solves all 6 equations is which is the solution to the original matrix equation.
C13.
Solution.
The given equation
gives a system of six equations in
Solving each of these equations, we see that the first three and the fifth all lead to the solution the fourth equation is true no matter what the value of but the last equation is only solved by Thus, the system has no solution, and the original matrix equation also has no solution.
C14.
Solution.
The given equation
gives a system of four equations in two variables
Solving this linear system by row-reducing the augmented matrix shows that is the only solution.
M10.
Describe matrices that are simultaneously both upper triangular and lower triangular.
Exercise Group.
In Chapter V we defined the operations of vector addition and vector scalar multiplication in Definition CVA and Definition CVSM. These two operations formed the underpinnings of the remainder of the chapter. We have now defined similar operations for matrices in Definition MA and Definition MSM. You will have noticed the resulting similarities between Theorem VSPCV and Theorem VSPM.
In Exercises M20–M25, you will be asked to extend these similarities to other fundamental definitions and concepts we first saw in Chapter V. This sequence of problems was suggested by Martin Jackson.
M20.
Suppose is a set of matrices from Formulate appropriate definitions for the following terms and give an example of the use of each.
- A linear combination of elements of
- A relation of linear dependence on
both trivial and nontrivial. is a linearly independent set.
M21.
Solution.
Suppose there exist constants and so that
Then
so that
The only solution is then and so that the set is a linearly independent set of matrices.
M22.
Solution.
Suppose that there exist constants and so that
Then, we have the matrix equality (Definition ME)
which yields the linear system of equations
By row-reducing the associated homogeneous system, we see that the only solution is so these matrices are a linearly independent subset of
M23.
Determine if the matrix is in the span of In other words, is If so write as a linear combination of the elements of
Solution.
The matrix is in the span of since
Note that if we were to write a complete linear combination of all of the matrices in then the fourth matrix would have a zero coefficient.
M24.
Suppose is the set of all symmetric matrices (Definition SYM). Find a set so that is linearly independent and
Solution.
Since any symmetric matrix is of the form
any symmetric matrix is a linear combination of the linearly independent vectors in set below, so that
(Something to think about: How do we know that these matrices are linearly independent?)
M25.
T13.
Prove Property CM of Theorem VSPM. Write your proof in the style of the proof of Property DSAM given in this section.
Solution.
For all and for all
With equality of each entry of the matrices and being equal Definition ME tells us the two matrices are equal.
T14.
Prove Property AAM of Theorem VSPM. Write your proof in the style of the proof of Property DSAM given in this section.
T17.
Prove Property SMAM of Theorem VSPM. Write your proof in the style of the proof of Property DSAM given in this section.
T18.
Prove Property DMAM of Theorem VSPM. Write your proof in the style of the proof of Property DSAM given in this section.
T25.
Prove that the transpose of an upper triangular matrix is a lower triangular matrix. Or vice-versa, your choice.
Exercise Group.
T30.
Prove that a skew-symmetric matrix is square. (Hint: study the proof of Theorem SMS.)
T31.
Prove that a skew-symmetric matrix must have zeros for its diagonal elements. In other words, if is skew-symmetric of size then for (Hint: carefully construct an example of a skew-symmetric matrix before attempting a proof.)
T32.
Prove that a matrix is both skew-symmetric and symmetric if and only if is the zero matrix. (Hint: one half of this proof is very easy, the other half takes a little more work.)
T33.
Suppose and are both skew-symmetric matrices of the same size and Prove that is a skew-symmetric matrix.
T34.
T35.
T36.
Suppose is a square matrix. Prove that there is a symmetric matrix and a skew-symmetric matrix such that In other words, any square matrix can be decomposed into a symmetric matrix and a skew-symmetric matrix (Proof Technique DC). (Hint: consider building a proof on Exercise MO.T34 and Exercise MO.T35.)
T37.
Prove that the decomposition in Exercise MO.T36 is unique (see Proof Technique U). (Hint: a proof can turn on Exercise MO.T31.)
You have attempted 1 of 4 activities on this page.