# Chapter 2. Matrices and vector coordinates

## 2.1 Matrix multiplication

In [§ 1.2](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/vector-spaces-and-bases/#sec:linear-algebra-i:linear-combinations-and-bases), a basis described a vector by its coefficients. A matrix uses such coefficients to form a new linear combination of its columns. This interpretation will explain both matrix multiplication and the representation of linear maps.

A matrix with $r$ rows and $c$ columns has size $r\times c$. Write $\mathrm M_{r\times c}(\mathbb F)$ for the space of $r$-by-$c$ matrices with entries in $\mathbb F$. More generally, $\mathrm M_{r\times c}(V)$ denotes the $r$-by-$c$ arrays with entries in a vector space $V$. The notation $\mathcal M_{r\times c}$ also denotes scalar-valued matrices of this size when the field is understood.

### Multiplication by columns

Let $A=[A_1,\ldots,A_s]\in\mathrm M_{r\times s}(\mathbb F)$. For a column $b=(b^1,\ldots,b^s)^T$, multiplication by $A$ is defined by the linear combination of its columns

$$
Ab=\sum_{k=1}^s A_kb^k\in\mathbb F^r.
$$

If $B=[B_1,\ldots,B_t]\in\mathrm M_{s\times t}(\mathbb F)$, define its product with $A$ column by column,

$$
AB=[AB_1,\ldots,AB_t]\in\mathrm M_{r\times t}(\mathbb F).
$$

Thus the number of columns of $A$ must equal the number of rows of $B$. We write $I_{r\times r}$ for the identity matrix and $0$ for a zero matrix of the required size.

### Reading a transformation from its columns

Consider the shear from [Subsection\* 1.2](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/vector-spaces-and-bases/#sec:linear-algebra-i:bases-to-transformations). In standard coordinates its matrix and its action are

$$
S=\begin{bmatrix}1&1\\0&1\end{bmatrix},
  \qquad
  S\begin{bmatrix}x\\y\end{bmatrix}
    =x\begin{bmatrix}1\\0\end{bmatrix}
      +y\begin{bmatrix}1\\1\end{bmatrix}
    =\begin{bmatrix}x+y\\y\end{bmatrix}.
$$

The first column is the image of $e_1=(1,0)^T$, and the second is the image of $e_2=(0,1)^T$. In particular, $S(e_1)=e_1$, so the first basis vector is fixed. For a general input, the first output coordinate is $x+y$, while the second is $y$. Multiplication by $(x,y)^T$ takes $x$ copies of the first image and $y$ copies of the second. This is precisely the rule

$$
S(xe_1+ye_2)=xS(e_1)+yS(e_2).
$$

Thus the matrix records the action on the basis, and the product recovers the action on every vector. The grid in [Figure 1.4](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/vector-spaces-and-bases/#fig:linear-algebra-i:shear-grid-overview) visualizes this same calculation at many input points at once.

The identity matrix provides the corresponding unchanged grid. Its columns are $e_1,e_2$, so $I_2(x,y)^T=(x,y)^T$. The distinction between applying a matrix to move a vector and using a matrix to change the coordinates of a fixed vector is developed in [§ 2.2](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/matrices-and-vector-coordinates/#sec:linear-algebra-i:change-of-basis-for-vectors).

### Exercises on matrix multiplication

### Exercise 2.1.1

Given a matrix $M$, let $M^j_k$ denote the entry in the $j$-th row and $k$-th column of $M$. Let $A\in\mathcal M_{r\times s}$ and $B\in\mathcal M_{s\times t}$. Show that the definition of matrix multiplication is the same as

$$
(AB)^j_l=\sum_{k=1}^s A^j_kB^k_l,
    \qquad 1\le j\le r,\quad 1\le l\le t.
$$

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:matrix-product-entries)

### Exercise 2.1.2

Let $A,B,C$ be scalar-valued matrices such that $(AB)C$ and $A(BC)$ are well defined. Use the formula for matrix multiplication in [Exercise 2.1.1](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/matrices-and-vector-coordinates/#ex:hw02:matrix-product-entries) to prove associativity, i.e., $(AB)C=A(BC)$.

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:matrix-product-associativity)

### Exercise 2.1.3

For $X,Y\in\mathcal M_{k\times l}$, let $P,Q\in\mathcal M_{k+l\times k+l}$ be given by

$$
P=\begin{bmatrix}I_{k\times k}&X\\0&I_{l\times l}\end{bmatrix}
    \quad\text{and}\quad
    Q=\begin{bmatrix}I_{k\times k}&Y\\0&I_{l\times l}\end{bmatrix}.
$$

1.  **(a)** Compute $PQ$.

2.  **(b)** Given $X$, find a matrix $Y$ such that $PQ=QP=I$.

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:block-shear-inverses)

### Exercise 2.1.4

1.  **(a)** Fix $s\ge1$. Prove that if $J\in\mathcal M_{r\times r}$ satisfies $JB=B$ for every $B\in\mathcal M_{r\times s}$, then $J=I_{r\times r}$.

2.  **(b)** Show by example that, for every $r\ge2$, $JB=B$ for a single nonzero $B$ does not imply $J=I_{r\times r}$. What happens when $r=1$?

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:characterizing-the-identity)

### Exercise 2.1.5

Recall that matrix multiplication is not necessarily commutative.

1.  **(a)** For $A\in\mathcal M_{r\times s}$ and $B\in\mathcal M_{p\times q}$, determine exactly when $AB$ and $BA$ are both defined.

2.  **(b)** Determine when $AB$ and $BA$ have the same size.

3.  **(c)** Given $r\ge2$, find matrices $A,B\in\mathcal M_{r\times r}$ such that $AB\ne BA$.

4.  **(d)** Let $E^i_j\in\mathcal M_{r\times r}$ be the matrix whose entry in row $i$ and column $j$ is $1$ and all of whose other entries are $0$. Prove that $\{E^i_j:1\le i,j\le r\}$ is a basis of $\mathcal M_{r\times r}$ and that

    $$
    E^i_jE^k_l=\delta^k_jE^i_l,
    $$

    where $\delta^k_j=1$ if $j=k$ and $0$ otherwise.

5.  **(e)** Prove that if $A\in\mathcal M_{r\times r}$ satisfies $AB=BA$ for every $B\in\mathcal M_{r\times r}$, then $A=cI_{r\times r}$ for some $c\in\mathbb F$.

6.  **(f)** Determine all $A\in\mathcal M_{r\times r}$ that commute with every $E^i_i$, $1\le i\le r$. Conclude that, for $r\ge2$, commuting with every diagonal matrix is a strictly weaker condition than the one in (e).

*Hint.* Compare the entries of $AE^i_j$ and $E^i_jA$.

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:matrix-commutation)

### Exercise 2.1.6

There are nonzero matrices $A$ and $B$ such that $AB=0$.

1.  **(a)** Find all $A\in\mathcal M_{2\times2}$ with $A^2=0$.

2.  **(b)** Find $A,B\in\mathcal M_{2\times2}$ with $AB=0$ and $BA\ne0$.

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:zero-products)

### Exercise 2.1.7

Prove that the set of upper triangular matrices

$$
\{A\in\mathcal M_{r\times r}:A^j_k=0\text{ whenever }j>k\}
$$

is a subspace of $\mathcal M_{r\times r}$, compute its dimension, and prove that it is closed under matrix multiplication.

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:upper-triangular-subspace)

### Exercise 2.1.8

Let $\mathbb F=\mathbb{R}$ or $\mathbb{C}$, and let

$$
A=\begin{bmatrix}2&3\\4&-1\end{bmatrix},\qquad
    B=\begin{bmatrix}0&1\\1&-1\end{bmatrix}.
$$

1.  **(a)** Compute $AB-BA$.

2.  **(b)** Show that $X\in\mathcal M_{2\times2}$ satisfies $AX=XA$ if and only if $X=pI+qA$ for some $p,q\in\mathbb F$.

3.  **(c)** Show that $X=0$ is the only $X\in\mathcal M_{2\times2}$ with $AX=XB$.

4.  **(d)** Show that $A^2=A+14I$.

5.  **(e)** Use this to write $A^3$ in the form $pA+qI$.

6.  **(f)** Use this to find $N\in\mathcal M_{2\times2}$ such that $AN=NA=I$.

[Solution in the appendix](https://xyzmaths.org/notes/linear-algebra/appendices/exercise-solutions/#sol:hw02:two-by-two-matrix-identities)

## 2.2 Change of basis formula for vectors

The coordinates introduced by a basis describe a vector relative to that basis. A second basis gives a second description of the same vector. The matrix in this section translates between those descriptions. When a linear transformation is applied, it produces an output vector, as in the shear of [Figure 1.4](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/vector-spaces-and-bases/#fig:linear-algebra-i:shear-grid-overview). Both calculations use matrices because both reconstruct vectors from linear combinations.

Let $E=[e_1,\ldots,e_n]$ and $F=[f_1,\ldots,f_n]$ be two ordered bases of $V$. Each vector $f_j$ has coordinates in the basis $E$, so there is a matrix $M\in\mathbb F^{n\times n}$ whose $j$-th column contains those coordinates. In matrix notation,

$$
F=EM.
$$

[![The same vector v in two bases of the real plane, shown schematically. Dashed lines complete the components. The coordinates satisfy a=Mb when F=EM.](https://xyzmaths.org/notes/linear-algebra/figures/vector-basis-coordinates.svg)](https://xyzmaths.org/notes/linear-algebra/figures/vector-basis-coordinates.svg "Open original SVG")

Figure 2.1. The same vector $v$ in two bases of the real plane, shown schematically. Dashed lines complete the components. The coordinates satisfy $a=Mb$ when $F=EM$.

Because $F$ is also a basis, there is a matrix $N$ with $E=FN$. Substituting these expressions into one another gives $E=EMN$ and $F=FNM$. Uniqueness of coefficients in each basis gives $MN=I_n$ and $NM=I_n$. Thus $N=M^{-1}$. The change-of-basis matrix is invertible, and it converts coordinates in either direction.

If $v\in V$ has coordinate columns $a$ in basis $E$ and $b$ in basis $F$, then $v=Ea=Fb$. Using $F=EM$,

$$
v=Fb=EMb,
  \qquad a=Mb,
  \qquad b=M^{-1}a.
$$

Thus $M$ converts $F$-coordinates to $E$-coordinates, and $M^{-1}$ converts $E$-coordinates to $F$-coordinates.

The vector stays fixed while its coordinate column changes. [Figure 2.1](https://xyzmaths.org/notes/linear-algebra/linear-algebra-i/matrices-and-vector-coordinates/#fig:linear-algebra-i:vector-basis-coordinates) shows the two decompositions in the real plane.
