# Matrix Algebra

Page
Matrix Algebra – HMC Calculus Tutorial

We review here some of the basic definitions and elementary algebraic operations on matrices.

There are many applications as well as much interesting theory revolving around these concepts, which we encourage you to explore after reviewing this tutorial.

A matrix is simply a retangular array of numbers. For example, $$A = \left[ \begin{array}{llcl} a_{11} & a_{12} & \cdots & a_{1n}\\ a_{21} & a_{22} & \cdots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ a_{m1} & a_{m2} & \cdots & a_{mn}\\ \end{array} \right]$$ is a $m\times n$ matrix ($m$ rows, $n$ columns), where the entry in the $i^{th}$ row and $j^{th}$ column is $a_{ij}$. We often write $A = [a_{ij}]$.

#### Some Terminology

For an $n \times n$ square matrix A, the elements $a_{11},a_{22},\ldots,a_{nn}$ form the main diagonal of the matrix. The sum $\sum\limits_{k=1}^{n}a_{kk}$ of the elements on the main diagonal of $A$ is called the trace of $A$.

The matrix $A^{T}=[a_{ji}]$ formed by interchanging the rows and columns of $A$ is called the transpose of $A$. If $A^{T}=A$, the matrix $A$ is symmetric.

###### Example

Let $B= \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right]$. The trace of $B$ is $6 + (-6) =0$.

The transpose of $B$ is $B^{T} = \left[ \begin{array}{ll} 6 & -4\\ 9 & -6\\ \end{array} \right]$.

#### Addition and Subtraction of Matrices

To add or subtract two matrices of the same size, simply add or subtract corresponding entries. That is, if $B=[b_{ij}]$ and $C=[c_{ij}]$, $$B + C = [b_{ij} + c_{ij}] {\small\textrm{ and }} B-C = [b_{ij} – c_{ij}].$$

###### Example

For $B = \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right]$ and $C = \left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right]$, $$B + C = \left[ \begin{array}{cc} 6 +1 & 9+2 \\ -4+(-1) & -6+0\\ \end{array} \right] = \left[ \begin{array}{rr} 7 & 11 \\ -5 & -6\\ \end{array} \right]$$ $$B-C = \left[ \begin{array}{cc} 6 -1 & 9-2 \\ -4-(-1) & -6-0\\ \end{array} \right] = \left[ \begin{array}{rr} 5 & 7 \\ -3 & -6\\ \end{array} \right].$$

The $m\times n$ zero matrix, 0, for which every entry is 0, has the property that for any $m\times n$ matrix $A$, $$A+\mathbf{0} = A.$$

#### Scalar Multiplication

To multiply a matrix $A$ by a number $c$ (a “scalar”), multiply each entry of $A$ by $c$. That is, $$cA=[ca_{ij}].$$

###### Example

Using the matrix $B= \left[ \begin{array}{rr} 6 & 9\\ -4 &-6\\ \end{array} \right]$ from the previous example, $$3B = 3\left[ \begin{array}{rr} 6 & 9\\ -4 &-6\\ \end{array}\right] = \left[ \begin{array}{rr} 18 & 27\\ -12 &-18\\ \end{array}\right].$$

#### Matrix Multiplication

Let $X$ be and $m \times n$ matrix and $Y$ be an $n \times p$ matrix. Then the product $XY$ is the $m\times p$ matrix whose $(i,j)^{th}$ entry is given by $$\sum^{n}_{k=1} x_{ik}y_{kj}.$$

#### Notes

• The product $XY$ is only defined if the number of columns of $X$ is the same as the number of rows of $Y$.

• $XY$ and $YX$ may very well not both be defined. If they both do exist, they are not necessarily equal and in fact might not even be of the same size.
###### Example

For the matrices $B = \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right]$ and $C = \left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right]$, $${ BC = \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right] \left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right] = \left[ \begin{array}{cc} (6)(1)+(9)(-1) & (6)(2)+(9)(0)\\ (-4)(1)+(-6)(-1) & (-4)(2) + (-6)(0)\\ \end{array} \right] = \left[ \begin{array}{cc} -3 & 12 \\ 2 & -8\\ \end{array} \right]}$$ while $${ CB = \left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right] \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right] = \left[ \begin{array}{cc} (1)(6) + (2)(-4) & (1)(9) + (2)(-6)\\ (-1)(6) + (0)(-4) & (-1)(9) + (0)(-6)\\ \end{array} \right] = \left[ \begin{array}{cc} -2 & -3 \\ -6 & -9\\ \end{array} \right]}.$$

The $n\times n$ matrix having all main diagonal entries equal to 1 and all other entries equal to 0 is called the identity matrix $I$. For example, the $3\times 3$ matrix is $\left[ \begin{array}{lll} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\\ \end{array} \right]$. The $n \times n$ identity matrix has the property that if $A$ is any $n \times n$ matrix, $$AI = IA = A.$$

#### Inverse of a Matrix

Start with an $n \times n$ matrix $X$. Suppose the $n \times n$ matrix $Y$ has the property that $$XY = YX = I.$$ Then $Y$ is called the inverse of $X$ and is denoted $X^{-1}$.

#### Notes

• Only square matrices $X$ can have inverses. If X is not square, then for any Y the product XY will not be the same size matrix as the product YX , assuming both products exist.

• Not every square matrix has an inverse. If an inverse exists, it is unique.

• If a matrix has an inverse, the matrix is said to be invertible.

The inverse of a $2 \times 2$ matrix is simple to calculate: $${\small\textrm{If }} A=\left[ \begin{array}{rr} a & b\\ c & d\\ \end{array} \right], {\small\textrm{ then }} A^{-1} = \frac{1}{ad-bc} \left[ \begin{array}{rr} d & -b\\ -c & a\\ \end{array} \right].$$

###### Example

The inverse of $C = \left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right]$ is $$C^{-1} = \frac{1}{(1)(0)-(2)(-1)}\left[ \begin{array}{rr} 0 & -2\\ 1 & 1\\ \end{array} \right] = \frac{1}{2} \left[ \begin{array}{rr} 0 & -2\\ 1 & 1\\ \end{array} \right] = \left[ \begin{array}{rr} 0 & -1\\ 1/2 & 1/2\\ \end{array} \right].$$ Note that $CC^{-1} = \left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right]\left[ \begin{array}{rr} 0 & -1\\ 1/2 & 1/2\\ \end{array} \right] = \left[ \begin{array}{rr} 1 & 0\\ 0 & 1\\ \end{array} \right]$

$\quad$ and $C^{-1}C = \left[ \begin{array}{rr} 0 & -1\\ 1/2 & 1/2\\ \end{array} \right]\left[ \begin{array}{rr} 1 & 2 \\ -1 & 0\\ \end{array} \right] = \left[ \begin{array}{rr} 1 & 0\\ 0 & 1\\ \end{array} \right].$

Matrix $B = \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right]$ does not have an inverse.

#### Determinant of a Matrix

How did we know that $B = \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right]$ does not have an inverse?

The determinant of $A$, $\det A$, is a number with the property that $A$ is invertible if and only if $\det A \not= 0$.

For a $2 \times 2$ matrix $A=\left[ \begin{array}{rr} a & b\\ c & d\\ \end{array} \right]$, $\det A = ad -bc$.

###### Example

For $B = \left[ \begin{array}{rr} 6 & 9 \\ -4 & -6\\ \end{array} \right]$, $\det B = (6)(-6)- (9)(-4)=-36+36=0$, so $B$ is not invertible. That is, $B$ does not have an inverse.

For a $3 \times 3$, or larger, matrix $A$, things are a little more complicated:

Denote by $M_{ij}(A)$ the determinant of the matrix formed by deleting row $i$ and column $j$ for $A$.

Define $c_{ij}(A) = (-1)^{i+j}M_{ij}(A)$ to be the $(i,j)$ cofactor of $A$.

Then we can compute $\det A$ by the Laplace Expansion along any row or column of $A$:

Along row $i$: $$\det A = a_{i1}c_{i1}(A) + a_{i2}c_{i2}(A) + \ldots + a_{in}c_{in}(A).$$

Along column $j$: $$\det A = a_{1j}c_{1j}(A) + a_{2j}c_{2j}(A)+ \ldots + a_{nj}c_{nj}(A).$$

###### Example

Let $A = \left[ \begin{array}{rrr} 1 & -1 & 3\\ 1 & 0 & -1\\ 2 & 1 & 6\\ \end{array} \right].$

Along the first row,

$\begin{array}{rcl} \det A & = & (1) \left[ (0)(6) – (-1)(1) \right] – (-1)\left [ (1)(6)-(-1)(2) \right] + 3 \left[ (1)(1)-(0)(2) \right] \\ & = & (1)(1) + (1)(8)+(3)(1)\\ & = & 12. \end{array}$

Computing $\det A$ along the second column instead,

$\begin{array}{rcl} \det A & = & -(-1) \left[ (1)(6) – (-1)(2) \right] + ( 0)\left [ (1)(6)-(3)(2) \right] – 1 \left[ (1)(-1)-(3)(1) \right] \\ & = & (1)(8)+(0)(0)-(1)(-4)\\ & = & 12 {\small\textrm{ as expected.}} \end{array}$

#### Key Concepts

Let $A = [a_{ij}] {\small\textrm{ and }} B=[b_{ij}]$.

• Transpose $A^{T}$ of $A$:

$$A^{T}=[a_{ji}].$$

• Trace of $A$:

$$\sum_{k=1}^{n} a_{kk} {\small\textrm{ (for an }}n\times n {\small\textrm{ matrix }} A).$$

• Identity Matrix $I$:

the $n \times n$ matrix with 1’s on the main digonal and 0’s elsewhere.

• $A+B$ and $A-B$:

$$A+B = [a_{ij}+ b_{ij}] \phantom{.}$$ $$A-B = [a_{ij} -b_{ij}].$$

• Scalar Multiplication:

$$cA = [ca_{ij}].$$

• Matrix Product $AB$:

$(i,j)^{th}$ entry is $\sum\limits_{k=1}^{n} a_{ik}b_{kj}$, for an $m \times n$ matrix $A$ and an $n \times p$ matrix $B$.

• Inverse $A^{-1}$ of $A$:

$A^{-1}$ satisfies $AA^{-1} = A^{-1}A = I$. If $A = \left[ \begin{array}{ll} a & b\\ c & d\\ \end{array}\right]$, then $A^{-1} = \frac{1}{ad-bc} \left[ \begin{array}{rr} d & -b \\ -c & a \\ \end{array}\right].$

• Determinant $\det A$:

If $A = \left[ \begin{array}{ll} a & b\\ c & d\\ \end{array}\right]$, $\det A = ad-bc$. In general, $\qquad$ along row $i$: $\qquad\qquad$ $\det A = a_{i1}c_{i1}(A) + a_{i2}c_{i2}(A) + \ldots + a_{in}c_{in}(A)$. $\qquad$ along column $j$: $\qquad\qquad$ $\det A = a_{1j}c_{1j}(A) + a_{2j}C_{2j}(A)+ \ldots + a_{nj}c_{nj}(A)$.