Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

3.1: Matrices

We concluded Chapter 2.8 with the understanding that many practical problems in engineering require us to solve systems of linear equations at scale. Matrices and their operations will help us accomplish that goal.


Introduction¶

The easiest way to think of a matrix is as being a collection of vectors, written next to each other, in one big array of numbers. Suppose we have three vectors in R2\mathbb R^2:

[21],[āˆ’14],[30].\begin{bmatrix}2\\1\end{bmatrix},\qquad \begin{bmatrix}-1\\4\end{bmatrix},\qquad \begin{bmatrix}3\\0\end{bmatrix}.

Place them side by side, keeping their order:

A=[2āˆ’13140].A=\begin{bmatrix}2&-1&3\\1&4&0\end{bmatrix}.

Shape¶

Here AA has two rows and three columns, so A∈R2Ɨ3A\in\mathbb R^{2\times3}.

Here are several more matrices, with their shape underneath:

[10231āˆ’10422āˆ’21503]āŸ5Ɨ3[120āˆ’13042]āŸ2Ɨ4[21003āˆ’1402]āŸ3Ɨ3.\underbrace{\begin{bmatrix} 1&0&2\\3&1&-1\\0&4&2\\2&-2&1\\5&0&3 \end{bmatrix}}_{5\times3} \qquad \underbrace{\begin{bmatrix}1&2&0&-1\\3&0&4&2\end{bmatrix}}_{2\times4} \qquad \underbrace{\begin{bmatrix}2&1&0\\0&3&-1\\4&0&2\end{bmatrix}}_{3\times3}.

A square matrix has the same number of rows and columns. Square matrices are special in many ways, and we will spend time discussing them in detail.

Entries¶

We use capital letters such as AA and BB for matrices. The notation aija_{ij} denotes the entry of AA in row ii, column jj, counting from 1. In our original matrix,

a12=āˆ’1,a21=1,a23=0.a_{12}=-1,\qquad a_{21}=1,\qquad a_{23}=0.

For an arbitrary nƗdn\times d matrix,

A=[a11a12⋯a1da21a22⋯a2d⋮⋮⋱⋮an1an2⋯and].A=\begin{bmatrix} a_{11}&a_{12}&\cdots&a_{1d}\\ a_{21}&a_{22}&\cdots&a_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ a_{n1}&a_{n2}&\cdots&a_{nd} \end{bmatrix}.

Two matrices are equal if they have the same shape and equal entries at every corresponding position. Merely containing the same numbers is not enough.


Rows and columns as vectors¶

Return to

A=[2āˆ’13140].A=\begin{bmatrix}2&-1&3\\1&4&0\end{bmatrix}.

There are two groups of vectors embedded in this matrix:

  • The columns make up three vectors in R2\mathbb R^2:

    [21],[āˆ’14],[30].\begin{bmatrix}2\\1\end{bmatrix},\qquad \begin{bmatrix}-1\\4\end{bmatrix},\qquad \begin{bmatrix}3\\0\end{bmatrix}.
  • The rows make up two vectors in R3\mathbb R^3:

    [2āˆ’13],[140].\begin{bmatrix}2\\-1\\3\end{bmatrix},\qquad \begin{bmatrix}1\\4\\0\end{bmatrix}.

These are two ways to view the same matrix.

More generally, an nƗdn\times d matrix contains dd columns, viewed as vectors in Rn\mathbb R^n, and nn rows, viewed as vectors in Rd\mathbb R^d.

A subtlety is that these are different objects:

[2āˆ’13]and[2āˆ’13].\begin{bmatrix}2\\-1\\3\end{bmatrix} \qquad\text{and}\qquad \begin{bmatrix}2&-1&3\end{bmatrix}.

The first is a 3Ɨ13\times1 matrix, which we call a vector in R3\mathbb R^3. The second is a 1Ɨ31\times3 matrix, which we might call a row vector. In these notes, Rn\mathbb R^n refers to column vectors. When we discuss the vectors formed by a matrix’s rows, we write their entries vertically, as above.

Viewing a matrix as a collection of vectors lets us ask familiar questions:

  • What is the span of the columns of AA? These columns are vectors in R2\mathbb R^2, so their span is a subset of R2\mathbb R^2.

  • Are the rows of AA linearly independent? Here we ask whether the two vectors in R3\mathbb R^3 formed from the rows are linearly independent.

Example: A dataset¶

Suppose we survey five Math 124 students about their past week. For each student, we record hours spent studying, practice problems completed, and lectures attended. The following numbers are made up:

StudentStudy hoursPractice problemsLectures attended
Student 14122
Student 26182
Student 3381
Student 45152
Student 5261

Store the numerical values in a matrix, keeping the row and column order:

X=[412261823815152261]āŸ5Ɨ3.X=\underbrace{\begin{bmatrix}4&12&2\\6&18&2\\3&8&1\\5&15&2\\2&6&1\end{bmatrix}}_{5\times3}.

With one row per person and one column per feature (or variable), the two views have concrete meanings:

  • Each of the five rows is a vector in R3\mathbb R^3: three measurements about one student.

  • Each of the three columns is a vector in R5\mathbb R^5: one measurement recorded across all five students. For example, the first column contains everyone’s study hours.

We could instead choose one row per feature and one column per person:

[463521218815622121]āŸ3Ɨ5.\underbrace{\begin{bmatrix}4&6&3&5&2\\12&18&8&15&6\\2&2&1&2&1\end{bmatrix}}_{3\times5}.

Either arrangement works. We just need to say what the rows and columns represent.


Addition and scalar multiplication¶

Addition and scalar multiplication work just as they did for vectors.

For example,

[2āˆ’13140]+[āˆ’1203āˆ’25]=[113425].\begin{bmatrix}2&-1&3\\1&4&0\end{bmatrix} +\begin{bmatrix}-1&2&0\\3&-2&5\end{bmatrix} =\begin{bmatrix}1&1&3\\4&2&5\end{bmatrix}.

Both inputs have shape 2Ɨ32\times3, and so does their sum. A 2Ɨ32\times3 matrix and a 3Ɨ23\times2 matrix cannot be added, even though both contain six entries.

For example,

āˆ’2[2āˆ’13140]=[āˆ’42āˆ’6āˆ’2āˆ’80].-2\begin{bmatrix}2&-1&3\\1&4&0\end{bmatrix} =\begin{bmatrix}-4&2&-6\\-2&-8&0\end{bmatrix}.

We define subtraction by Aāˆ’B=A+(āˆ’1)BA-B=A+(-1)B. The zero matrix 0nƗd0_{n\times d} has nn rows, dd columns, and every entry equal to zero; A+0nƗd=AA+0_{n\times d}=A for any nƗdn\times d matrix AA.