Matrices¶
Vectors and matrices · Chapter 4.1 · Lecture notes (PDF) · Exercises: Matrices · Slides (PDF) · App: Matrix product · App: Determinant · App: Rank
1. Definition and transpose¶
Definition 1: Matrix
A matrix is a rectangular table of real numbers with \(m\) rows and \(n\) columns.
Given a matrix \(\boldsymbol{A}\in\R^{m\times n}\), we write:
-
The integers \(m\) and \(n\) are the dimensions of the matrix: \(m\) is the number of rows and \(n\) is the number of columns.
-
The quantity \([\boldsymbol A]_{i,j}\) (or \(a_{ij}\)) denotes the entry of \(\boldsymbol{A}\) in row \(i\) and column \(j\), for \(i\in\{1,2,\dots,m\}\) and \(j\in\{1,2,\dots,n\}\).
Example 1: Matrix
The matrix
is a matrix with \(m=2\) rows and \(n=3\) columns, where \(a_{11} = 1\), \(a_{12} = 2\), \(a_{13} = 3\), \(a_{21} = 4\), \(a_{22} = 5\), and \(a_{23} = 6\).
Definition 2: Transpose of a matrix
Given a matrix \(\boldsymbol A \in \R^{m \times n}\), the transpose of \(\boldsymbol A\), denoted by \(\boldsymbol A'\), is the \(n \times m\) matrix obtained by interchanging rows and columns:
-
The entry in position \((i,j)\) of the transpose matrix \(\boldsymbol A'\) is:
\[ a'_{ij} = a_{ji}, \quad \forall i \in \{1,2,\dots,n\},\; \forall j \in \{1,2,\dots,m\}. \]
Example 2: Transpose of a matrix
Given the matrix
its transpose is
1.1 Rows and columns¶
-
The \(i\)-th row of a matrix \(\boldsymbol{A}\) is denoted by
\[ R_i(\boldsymbol{A}) \qquad \text{or} \qquad \boldsymbol{A}_i \] -
The \(j\)-th column of a matrix \(\boldsymbol{A}\) is denoted by
\[ C_j(\boldsymbol{A}) \qquad \text{or} \qquad \boldsymbol{A}_j \] -
In both cases, we can simply use \(R_i\) or \(C_j\) when the matrix is clear from the context.
1.2 Minor matrices¶
- Let \(\boldsymbol A\in\R^{n\times m}\) be a matrix and let \(i\in\{1,2,\dots,n\}\), \(j\in\{1,2,\dots,m\}\). We denote by \(\boldsymbol A_{ij}\) the \((n-1)\times(m-1)\) matrix obtained from \(\boldsymbol A\) by deleting row \(i\) and column \(j\). The matrix \(\boldsymbol A_{ij}\) is called the minor matrix associated with the entry \(a_{ij}\).
Example 3: Minor matrix
Let
For \(i=2\) and \(j=3\), the minor matrix \(\boldsymbol A_{23}\in\R^{3\times 3}\) is obtained by deleting row \(2\) and column \(3\):
2. Sum of matrices and scalar multiplication¶
Given two matrices
their sum is the matrix
Given a scalar \(\lambda\in\R\) and a matrix
the scalar multiplication of \(\boldsymbol A\) by \(\lambda\) is the matrix
Example 4: Sum of matrices and scalar multiplication
Consider the matrices
Then
and, for \(\lambda=-2\),
2.1 Properties¶
The main properties of matrix sum and scalar multiplication are:
3. Matrix product¶
Given two matrices
their multiplication is the matrix
where the entry in position \((i,k)\), i.e., \([\boldsymbol A\boldsymbol B]_{ik}=\sum_{j=1}^{n} a_{ij}b_{jk}\), is the scalar product of the \(i\)-th row of \(\boldsymbol A\) and the \(k\)-th column of \(\boldsymbol B\).
Example 5: Matrix product
Consider the matrices
The product \(\boldsymbol A \boldsymbol B\) is:
The product \(\boldsymbol B \boldsymbol A\) is:
Example 6: Matrix product
Consider the matrices
The product \(\boldsymbol A\boldsymbol B\) is:
The product \(\boldsymbol B \boldsymbol A\) is:
In particular, \(\boldsymbol A\boldsymbol B \neq \boldsymbol B\boldsymbol A\).
3.1 Properties¶
The main properties of the matrix product (when dimensions are compatible) are:
In general, the matrix product is not commutative:
Try it in the lab
the same computation step by step: change the matrix and watch the steps change.
4. Special matrices¶
Definition 3: Square matrix
A matrix \(\boldsymbol A\in\R^{m\times n}\) is called a square matrix if it has the same number of rows and columns (\(m=n\)). In this case, \(\boldsymbol A\in\R^{n\times n}\) and it has the form:
Example 7: Square matrix
An example of a square matrix of size \(3\) is:
Definition 4: Identity matrix
A square matrix \(\boldsymbol I_n\in\R^{n\times n}\) is called the identity matrix if it has ones on the main diagonal and zeros elsewhere. It has the form:
-
Equivalently, the identity matrix satisfies
\[ [\boldsymbol I_n]_{ij}= \begin{cases} 1, & \text{if } i=j,\\ 0, & \text{if } i\neq j, \end{cases} \qquad \forall i,j\in\{1,2,\dots,n\}. \]
Example 8: Identity matrix
The identity matrix of size \(3\) is:
-
For any matrix \(\boldsymbol A \in \R^{m \times n}\), we have:
\[ \boldsymbol I_m \boldsymbol A = \boldsymbol A \qquad \text{and} \qquad \boldsymbol A \boldsymbol I_n = \boldsymbol A. \]
Definition 5: Diagonal matrix
A square matrix \(\boldsymbol D\in\R^{n\times n}\) is called diagonal if all its off-diagonal entries are zero. It has the form:
-
Equivalently, a diagonal matrix satisfies
\[ d_{ij}=0,\qquad \forall i,j\in\{1,2,\dots,n\}\ \text{with}\ i\neq j. \]
Example 9: Diagonal matrix
The matrix
is diagonal.
Definition 6: Symmetric matrix
A square matrix \(\boldsymbol Q\in\R^{n\times n}\) is called symmetric if it has the same entries with respect to the main diagonal (i.e., the entry in position \((i,j)\) equals the entry in position \((j,i)\)). It has the form:
-
Equivalently, a symmetric matrix satisfies
\[ q_{ij}=q_{ji},\qquad \forall i,j\in\{1,2,\dots,n\}. \] -
In matrix form, symmetry can be written as
\[ \boldsymbol Q'=\boldsymbol Q. \]
Definition 7: Upper triangular matrix
A square matrix \(\boldsymbol U\in\R^{n\times n}\) is called upper triangular if all its entries below the main diagonal are zero. It has the form:
-
Equivalently, an upper triangular matrix satisfies
\[ u_{ij}=0,\qquad \forall i,j\in\{1,2,\dots,n\}\ \text{with}\ i>j. \]
Example 10: Upper triangular matrix
The matrix
is upper triangular.
Definition 8: Lower triangular matrix
A square matrix \(\boldsymbol L\in\R^{n\times n}\) is called lower triangular if all its entries above the main diagonal are zero. It has the form:
-
Equivalently, a lower triangular matrix satisfies
\[ \ell_{ij}=0,\qquad \forall i,j\in\{1,2,\dots,n\}\ \text{with}\ i<j. \]
Example 11: Lower triangular matrix
The matrix
is lower triangular.
4.1 Permutation matrices¶
- Permutation matrices are square matrices obtained by permuting the rows (or equivalently, the columns) of the identity matrix. They encode permutations of indices and implement row/column reorderings through matrix multiplication.
Given an ordering (permutation) \(\pi\) of \(\{1,\dots,n\}\), we denote by \(\boldsymbol P_{\pi}\) the permutation matrix obtained from \(\boldsymbol I_n\) by reordering its rows according to \(\pi\), i.e., placing row \(\pi(1)\) first, then row \(\pi(2)\), \(\dots\), and finally row \(\pi(n)\).
-
Row reordering by left multiplication. Given \(\boldsymbol A \in \R^{m \times n}\) and \(\boldsymbol P_{\pi} \in \R^{m \times m}\), the matrix
\[ \boldsymbol P_{\pi}\boldsymbol A \]consists of the rows of \(\boldsymbol A\) reordered according to the permutation \(\pi\) (row \(\pi(1)\) becomes the first row, row \(\pi(2)\) becomes the second row, etc.).
-
Column reordering by right multiplication. Given \(\boldsymbol A \in \R^{m \times n}\) and \(\boldsymbol P_{\pi} \in \R^{n \times n}\), the matrix
\[ \boldsymbol A\boldsymbol P_{\pi}' \](note the transpose: \(\boldsymbol P_{\pi}'\) is obtained from \(\boldsymbol I_n\) by reordering its columns according to \(\pi\)) consists of the columns of \(\boldsymbol A\) reordered according to the permutation \(\pi\) (column \(\pi(1)\) becomes the first column, column \(\pi(2)\) becomes the second column, etc.).
Example 12: Row reordering via permutation matrix
Consider the matrix
Given the desired row ordering \(\pi=(3,1,2)\) (i.e., row \(3\) first, then row \(1\), then row \(2\)), we use the permutation matrix \(\boldsymbol P_{\pi}\) obtained from \(\boldsymbol I_3\) by reordering its rows as \((3,1,2)\):
Then:
The rows of \(\boldsymbol A\) have been reordered according to \(\pi=(3,1,2)\).
Example 13: Column reordering via permutation matrix
Consider the matrix
Given the desired column ordering \(\pi=(2,3,1)\) (i.e., column \(2\) first, then column \(3\), then column \(1\)), we use the permutation matrix \(\boldsymbol P_{\pi}\) obtained from \(\boldsymbol I_3\) by reordering its rows as \((2,3,1)\), and its transpose:
Then:
The columns of \(\boldsymbol A\) have been reordered according to \(\pi=(2,3,1)\).
4.2 Inverse matrices¶
Definition 9: inverse matrix
A square matrix \( \boldsymbol A \in \R^{n\times n} \) is invertible if there exists a matrix \( \boldsymbol A^{-1} \in \R^{n\times n} \) such that
Such a matrix \( \boldsymbol A^{-1} \) is called the inverse of \( \boldsymbol A \).
- If it exists, the inverse matrix \( \boldsymbol A^{-1} \) is unique.
4.3 Semidefinite matrices¶
Definition 10: semidefinite matrices
A square symmetric matrix \( \boldsymbol Q \in \R^{n \times n} \) is
-
positive semidefinite if
\[ \boldsymbol x' \boldsymbol Q \, \boldsymbol x \ge 0, \qquad \forall \boldsymbol x \in \R^n \] -
positive definite if
\[ \boldsymbol x' \boldsymbol Q \, \boldsymbol x > 0, \qquad \forall \boldsymbol x \in \R^n \setminus \{\boldsymbol 0\} \] -
negative semidefinite if
\[ \boldsymbol x' \boldsymbol Q \, \boldsymbol x \le 0, \qquad \forall \boldsymbol x \in \R^n \] -
negative definite if
\[ \boldsymbol x' \boldsymbol Q \, \boldsymbol x < 0, \qquad \forall \boldsymbol x \in \R^n \setminus \{\boldsymbol 0\} \]
Example 14: positive semidefinite matrix
-
The identity matrix
\[ \boldsymbol I= \begin{pmatrix} 1 & 0\\[1ex] 0 & 1 \\ \end{pmatrix} \]is positive semidefinite since:
\[ \begin{pmatrix} x_1 & x_2 \end{pmatrix} \begin{pmatrix} 1 & 0\\[1ex] 0 & 1 \\ \end{pmatrix} \begin{pmatrix} x_1 \\[1ex] x_2 \\ \end{pmatrix} = x_1^2 + x_2^2 \ge 0, \qquad \forall \begin{pmatrix}x_1\\x_2\end{pmatrix} \in \R^2. \] -
The matrix
\[ \begin{pmatrix} 2 & -1 \\[1ex] -1 & 2 \end{pmatrix} \]is positive semidefinite since:
\[\begin{align*} \begin{pmatrix} x_1 & x_2 \end{pmatrix} \begin{pmatrix} 2 & -1 \\[1ex] -1 & 2 \end{pmatrix} \begin{pmatrix} x_1 \\[1ex] x_2 \end{pmatrix} &= 2x_1^2 - 2x_1x_2 + 2x_2^2 \\[1ex] &= x_1^2 + (x_1 - x_2)^2 + x_2^2 \ge 0, \qquad \forall \begin{pmatrix}x_1\\x_2\end{pmatrix} \in \R^2. \end{align*}\]
5. Determinant¶
-
Determinant of a \(1\times 1\) matrix. Let
\[ \boldsymbol A= \begin{pmatrix} a \end{pmatrix}\in\R^{1\times 1}. \]Then
\[\begin{equation} \det(\boldsymbol A)=a. \end{equation}\] -
Determinant of a \(2\times 2\) matrix. Let
\[ \boldsymbol A= \begin{pmatrix} a & b\\ c & d \end{pmatrix}\in\R^{2\times 2}. \]Then
\[\begin{equation} \det(\boldsymbol A)=ad-bc. \end{equation}\] -
Determinant of a \(3\times 3\) matrix (Sarrus rule). Let
\[ \boldsymbol A= \begin{pmatrix} a & b & c\\ d & e & f\\ g & h & i \end{pmatrix}\in\R^{3\times 3}. \]Then
\[\begin{equation} \det(\boldsymbol A) = aei + bfg + cdh \;-\; ceg - bdi - afh. \end{equation}\]
Example 15: determinant of a \(2\times2\) matrix
Let
Then
Example 16: determinant of a \(3\times3\) matrix
Let
Using Sarrus:
Hence
5.1 Laplace expansion¶
Let \(\boldsymbol A\in\R^{n\times n}\) be a square matrix. The determinant \(\det(\boldsymbol A)\) can be computed recursively by Laplace expansion along any row or column.
For any row \(i\in\{1,2,\dots,n\}\), we have:
For any column \(j\in\{1,2,\dots,n\}\), we have:
Where \(C_{ij}\) is the cofactor of the entry \(a_{ij}\), defined by
where \(\boldsymbol A_{ij}\) is the minor matrix obtained from \(\boldsymbol A\) by deleting row \(i\) and column \(j\).
Example 17: Determinant via Laplace expansion
Let
We expand along the second column (it contains a zero):
Compute the cofactors:
Therefore,
5.2 Determinant of triangular and diagonal matrices¶
- For triangular matrices (upper or lower), the determinant has a particularly simple form: it is the product of the diagonal entries.
If \(\boldsymbol U \in \R^{n \times n}\) is an upper triangular matrix, then
If \(\boldsymbol L \in \R^{n \times n}\) is a lower triangular matrix, then
-
In particular, for a diagonal matrix \(\boldsymbol D \in \R^{n \times n}\):
\[ \det(\boldsymbol D) = \prod_{i=1}^{n} d_{ii}. \] -
For the identity matrix \(\boldsymbol I_n\):
\[ \det(\boldsymbol I_n) = 1. \]
Example 18: Determinant of an upper triangular matrix
Let
Then
Example 19: Determinant of a lower triangular matrix
Let
Then
Example 20: Determinant of a diagonal matrix
Let
Then
5.3 Properties of determinants¶
- The determinant satisfies several important algebraic properties that make its computation and application more efficient.
Let \(\boldsymbol A, \boldsymbol B \in \R^{n \times n}\) be square matrices and \(\lambda \in \R\) be a scalar. Then:
-
From properties \(\eqref{det_prod}\) and \(\eqref{det_identity}\), if \(\boldsymbol A\) is invertible:
\[ \det(\boldsymbol A) \cdot \det(\boldsymbol A^{-1}) = \det(\boldsymbol A \boldsymbol A^{-1}) = \det(\boldsymbol I_n) = 1, \]which gives property \(\eqref{det_inverse}\).
-
Property \(\eqref{det_scalar}\) shows that scalar multiplication affects the determinant by the \(n\)-th power of the scalar (not linearly).
-
Property \(\eqref{det_transpose}\) implies that row operations and column operations have symmetric effects on the determinant.
Example 21: Determinant of a product
Let
We have:
The product is:
Then:
Example 22: Determinant of a transpose
Let
We have:
Therefore, \(\det(\boldsymbol A') = \det(\boldsymbol A)\).
Example 23: Determinant of a scalar multiple
Let
Then:
We have:
Since \(n=2\), we verify:
Example 24: Determinant of an inverse
Let
We have:
The inverse matrix is:
Then:
A matrix \( \boldsymbol A \) is invertible if and only if \( \det(\boldsymbol A)\neq 0 \).
Try it in the lab
the same computation step by step: change the matrix and watch the steps change.
6. Rank¶
Definition 11: rank of a matrix
Let \( \boldsymbol A \in \R^{m\times n} \). The rank of \( \boldsymbol A \), denoted by \( \mathrm{rank}(\boldsymbol A) \), is the maximum number of linearly independent columns of \( \boldsymbol A \).
-
The columns of \(\boldsymbol A\) are vectors of \(\R^{m}\), and linear independence is meant in the sense of the definition given in the chapter on vectors: \(\boldsymbol v_1,\dots,\boldsymbol v_k\) are linearly independent if \(\lambda_1\boldsymbol v_1+\dots+\lambda_k\boldsymbol v_k=\boldsymbol 0\) implies \(\lambda_1=\dots=\lambda_k=0\).
-
Equivalently, \( \mathrm{rank}(\boldsymbol A) \) is the maximum number of linearly independent rows of \( \boldsymbol A \).
-
We always have
\[ \mathrm{rank}(\boldsymbol A)\le \min\{m,n\}. \] -
If \( \boldsymbol A \in \R^{n\times n} \) is square, then
\[ \mathrm{rank}(\boldsymbol A)=n \quad \Longleftrightarrow \quad \det(\boldsymbol A)\neq 0. \]
Example 25: rank of a matrix
Let
The second row is a multiple of the first one:
Hence the two rows are linearly dependent, so there is only one linearly independent row. Therefore,
Example 26: rank of a \(3\times 3\) matrix
Let
The third column is the sum of the first two:
hence the three columns are linearly dependent and \(\mathrm{rank}(\boldsymbol A)\le 2\). On the other hand, the first two columns are linearly independent: \(\lambda_1 C_1(\boldsymbol A)+\lambda_2 C_2(\boldsymbol A)=\boldsymbol 0\) gives \(\lambda_1=0\) (first entry) and \(\lambda_2=0\) (third entry). Therefore,
Consistently, expanding along the first row, \(\det(\boldsymbol A)=1\cdot(1\cdot 1-3\cdot 1)-0+1\cdot(2\cdot 1-1\cdot 0)=-2+2=0\).
Try it in the lab
the same computation step by step: change the matrix and watch the steps change.
Exercises and lab¶
- Exercises · the exercise sheet of this chapter: 12 exercises with worked solutions
- Lab · Matrix product — Row by column, one entry at a time.
- Lab · Determinant — Laplace expansion along the row or column you choose, or the Sarrus rule
- Lab · Rank — The rank as the number of pivots of the row echelon form.