Math for economyMM1005

How to find your way

  1. 1Search for the word that confuses you — the box at the top searches the whole course.
  2. 2Look it up in Concepts. Every concept links to the section that explains it. Concepts →
  3. 3Read the Watch out and Common error boxes: they show the mistakes that are actually made.
  4. 4Still stuck? Bring the question to the exercise session or send an email.

Lecturer: Eric Ahlqvist, eric.ahlqvist@math.su.se · Put “MM1005” in the subject line.

← 11
Lecture 12 Matrices, vectors, and the algebra of linear systems
13 →
12 Matrices

Matrices, vectors, and the algebra of linear systems

Can a system of many equations in many unknowns be written as a single equation, as short as $ax=b?$ This lecture says yes, and the price is one new rule of multiplication.

The course now changes subject. Nothing from Lectures 2–11 is needed below: no derivatives, no optimisation, no limits. What is needed is the linear equation of Lecture 1, and the observation that one such equation is rarely enough — problems come with several equations and several unknowns at once.

Handling such a system means handling a whole rectangular block of coefficients as a single object. That object is a matrix, and this lecture builds its algebra: what matrices are, how to add them, how to multiply them, and why the multiplication rule looks the way it does. The last question has a clean answer, and it is the point of the lecture.

⏱ 55 min read§ 6 sections

After this lecture you can

  • read and write an $m\times n$ matrix with the row index first, and tell which entries exist
  • write down the coefficient matrix and the right-hand side of a linear system, with a zero for every unknown that is missing from an equation
  • decide from the orders alone whether $\mathbf{A}+\mathbf{B},$ $\mathbf{A}\mathbf{B}$ and $\mathbf{B}\mathbf{A}$ exist, and what order each has
  • add matrices, multiply them by scalars and compute inner products, and say why prices times quantities is a number
  • compute a matrix product entry by entry, and explain why the rule is the one that substituting one linear system into another forces
  • write any linear system as $\mathbf{A}\mathbf{x}=\mathbf{b},$ and check a proposed solution with one product
1

Matrices and vectors

A table of monthly sales has the commodities down the side and the outlets across the top. Which number is $a_{73}?$

Row first, then column. The entry $a_{ij}$ sits where row $i$ meets column $j.$ The line under the grid reads the sales matrix of Example 12.4: $a_{73}=225$ is commodity $7$ at outlet $3,$ not the reverse. (The labels are small on a phone; this caption says what they say.)

Matrices are written as bold capitals, $\mathbf{A},$ $\mathbf{B}.$ A matrix with only one row is a row vector and one with only one column a column vector; both are written as bold lower-case letters, $\mathbf{a},$ $\mathbf{x},$ and their entries are called components. A vector with $n$ components is an $n$-vector.

If $m=n$ the matrix is square of order $n$, and then $a_{11},a_{22},\dots,a_{nn}$ form its main diagonal. Only a square matrix has one. (The order $m\times n$ is read "$m$ by $n$"; the dots $\dots$ and $\cdots$ stand for the entries that are not written out.)

So a single matrix equation between two $m\times n$ matrices is $mn$ ordinary equations at once. That compression is the whole reason for the notation.

Example 12.3

A matrix from a formula

Write out $\mathbf{A}=(a_{ij})_{3\times 4}$ with $a_{ij}=2i-j.$

Try it yourself first. Then open one step at a time.

Example 12.4

What the indices mean

A chain has four outlets, each selling eight commodities. Let $a_{ij}$ be the value of sales of commodity $i$ at outlet $j$ in a given month. The data form an $8\times 4$ matrix $\mathbf{A}$: eight rows, one per commodity, and four columns, one per outlet. Then $a_{73}=225$ says that outlet $3$ sold $\text{\textdollar}225$ of commodity $7.$

Try it yourself first. Then open one step at a time.

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

$$\mathbf{A} = \begin{pmatrix} 3 & 5 & 1 \\ 2 & 0 & 4 \end{pmatrix}$$

What is $a_{23}$, and what is $a_{32}$?

2

Systems of linear equations

Two equations, three unknowns, and one unknown missing from the second equation. How do you write that as a block of numbers?

Nothing requires $m=n:$ there may be more equations than unknowns, or fewer.

The array of coefficients in (12.1) is an $m\times n$ matrix, the coefficient matrix $\mathbf{A}=(a_{ij})_{m\times n},$ and the right-hand sides form a column vector $\mathbf{b}.$ Note that the index convention of Definition 12.1 and the one in (12.1) agree: $i$ counts equations, which are rows, and $j$ counts variables, which are columns.

In words: a system of linear equations has constant terms on the right, and a solution must satisfy every equation at once. A system with a solution is consistent; one with none is inconsistent.

Recap Recap: linear equations

An equation is linear when each unknown appears only to the first power, multiplied by a constant, and never multiplied by another unknown. So $\sqrt3\,x_{1}+2x_{2}=5$ is linear, while equations containing $\sqrt{x_{1}},$ $x_{1}^{2}$ or $8x_{1}x_{2}$ are not.

With two unknowns a linear equation is a straight line, the graph of a linear function when it can be solved for $y.$ Two of them behave as Fact 1.7 says: exactly one solution (the lines cross), none (parallel and distinct) or infinitely many (the same line). Comparing slopes tells which. This lecture keeps the equations linear and lets their number grow.

Guess first. The question below is the next example. Answer it before you read on: what happens to an unknown that is simply absent from one of the equations?

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

$$\begin{aligned} 3x_1 + 2x_2 - x_3 &= 4\\ x_1 \quad\;\; - 5x_3 &= 7 \end{aligned}$$

What is the coefficient matrix $\mathbf{A}$?

Example 12.7

A missing unknown is a zero

The system $$ \begin{aligned} 3x_{1} + 2x_{2} - x_{3} &= 4\\ x_{1} \phantom{{}+2x_{2}} \;-\; 5x_{3} &= 7 \end{aligned} $$ has two equations and three unknowns. What are its coefficient matrix and its right-hand side?

Try it yourself first. Then open one step at a time.

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

What is the coefficient matrix of the system $$ \begin{aligned} 2x_{1}-x_{3}&=5\,,\\ x_{2}+4x_{1}&=1\,? \end{aligned} $$

3

Addition and scalar multiples

This month's sales and next month's sales are two tables of the same shape. What is the two months together, and what is the change?

Both operations act entry by entry, in the only way one could reasonably guess. ($\alpha$ is the Greek letter alpha; a scalar is just a number, and $\alpha\mathbf{A}$ multiplies every entry by it.)

In the chain of shops of Example 12.4: if $\mathbf{A}$ is this month's sales and $\mathbf{B}$ next month's, then $\mathbf{A}+\mathbf{B}$ is the two months together and $\mathbf{B}-\mathbf{A}$ the change, with a negative entry where sales fell.

Fact 12.10Rules for addition and scalars#

Let $\mathbf{A},\mathbf{B},\mathbf{C}$ be $m\times n$ matrices, let $\alpha,\beta$ be scalars, and let $\mathbf{0}$ be the $m\times n$ zero matrix, all of whose entries are $0$. Then $$ \begin{array}{l} (\mathbf{A}+\mathbf{B})+\mathbf{C}=\mathbf{A}+(\mathbf{B}+\mathbf{C})\,, \\ \mathbf{A}+\mathbf{B}=\mathbf{B}+\mathbf{A}\,,\\[4pt] \mathbf{A}+\mathbf{0}=\mathbf{A}\,, \\ \mathbf{A}+(-\mathbf{A})=\mathbf{0}\,,\\[4pt] (\alpha+\beta)\mathbf{A}=\alpha\mathbf{A}+\beta\mathbf{A}\,, \\ \alpha(\mathbf{A}+\mathbf{B})=\alpha\mathbf{A}+\alpha\mathbf{B}\,. \end{array} $$

Every one of these holds entry by entry, where it is the corresponding rule for ordinary numbers. Associativity is what lets us write $\mathbf{A}+\mathbf{B}+\mathbf{C}$ without brackets. (The zero matrix plays the part of the number $0;$ $\beta$ is the Greek letter beta.)

Example 12.11

Entry by entry

With $\mathbf{A}=\begin{pmatrix} 1 & 2\\ 0 & -1\end{pmatrix}$ and $\mathbf{B}=\begin{pmatrix} 4 & -2\\ 3 & 5\end{pmatrix},$ compute $\mathbf{A}+\mathbf{B},$ $3\mathbf{A}$ and $\mathbf{A}-\mathbf{B}.$

Try it yourself first. Then open one step at a time.

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

$\mathbf{A}$ is $2\times3,$ $\mathbf{B}$ is $3\times2,$ $\mathbf{r}=(1,2,3)$ is a row vector and $\mathbf{c}$ is the column vector with the same entries $1,2,3.$ Which of these is defined?

4

Vectors and the inner product

You buy $5,$ $3,$ $6$ and $7$ kilos of four fruits at $4,$ $5,$ $3$ and $8$ dollars a kilo. Which operation on the two lists gives the bill?

A vector is a matrix, so it inherits everything above: $n$-vectors are added componentwise and scaled componentwise, and Fact 12.10 applies unchanged.

If $\mathbf{a}$ and $\mathbf{b}$ are commodity bundles, and $t$ people each buy $\mathbf{a}$ while $s$ people each buy $\mathbf{b},$ then $t\mathbf{a}+s\mathbf{b}$ is what the $t+s$ of them bought between them. One new operation is needed, and it is the one that turns quantities into money.

(So a linear combination is a bundle of bundles. For instance, with $\mathbf{a}=(1,2)$ and $\mathbf{b}=(3,0),$ $2\mathbf{a}+\mathbf{b}=(2+3,\,4+0)=(5,4).$)

The sign $\sum_{j=1}^{n}$ says: add the terms for $j=1,2,\dots,n.$ The dimension of a vector is its number of components. The inner product multiplies in pairs and adds.

Example 12.15

Why it is the operation one wants

Buy the bundle $\mathbf{x}=(5,3,6,7)$ kilos of four fruits at prices $\mathbf{p}=(4,5,3,8)$ dollars per kilo. What is the bill?

Try it yourself first. Then open one step at a time.

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

$\mathbf{p} = (4, 5, 3)$ is a price vector and $\mathbf{x} = (2, 0, 6)$ a quantity vector.

What is $\mathbf{p} \cdot \mathbf{x}$?

Fact 12.16Rules for the inner product#

For $n$-vectors $\mathbf{a},\mathbf{b},\mathbf{c}$ and a scalar $\alpha$:

  1. $\mathbf{a}\cdot\mathbf{b}=\mathbf{b}\cdot\mathbf{a}$;
  2. $(\alpha\mathbf{a})\cdot\mathbf{b} =\mathbf{a}\cdot(\alpha\mathbf{b}) =\alpha(\mathbf{a}\cdot\mathbf{b})$;
  3. $\mathbf{a}\cdot(\mathbf{b}+\mathbf{c}) =\mathbf{a}\cdot\mathbf{b}+\mathbf{a}\cdot\mathbf{c}$;
  4. $\mathbf{a}\cdot\mathbf{a}\ge 0$, with equality if and only if $\mathbf{a}=\mathbf{0}$.

(The rules (a)–(d) are the four lines of the Fact.) In prices and quantities, (b) says that doubling every price doubles the bill, and (c) that the bill for two bundles bought together is the sum of the two bills.

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

Two $n$-vectors have $\mathbf{a}\cdot\mathbf{b}=7.$ What is $(3\mathbf{a})\cdot(2\mathbf{b})?$

5

Matrix multiplication

Each $y_{j}$ is a linear expression in $x_{1},x_{2},$ and each $z_{i}$ one in $y_{1},y_{2},y_{3}.$ What is each $z_{i}$ in terms of $x_{1},x_{2}?$

Addition was forced on us by the entries. Multiplication is not: the useful rule is not the entrywise one. To see where it comes from, substitute one linear system into another.

Suppose three variables $y_{1},y_{2},y_{3}$ are given in terms of $x_{1},x_{2},$ and two variables $z_{1},z_{2}$ are given in terms of the $y$'s: $$ \begin{aligned} y_{1} &= b_{11}x_{1}+b_{12}x_{2}\\ y_{2} &= b_{21}x_{1}+b_{22}x_{2}\\ y_{3} &= b_{31}x_{1}+b_{32}x_{2} \end{aligned} $$ $$ \begin{aligned} z_{1} &= a_{11}y_{1}+a_{12}y_{2}+a_{13}y_{3}\\ z_{2} &= a_{21}y_{1}+a_{22}y_{2}+a_{23}y_{3}\,. \end{aligned} $$ Then the $z$'s depend on the $x$'s. Substituting and collecting the terms in $x_{1},$ $$ \begin{aligned} z_{1} &= (a_{11}b_{11}+a_{12}b_{21}+a_{13}b_{31})\,x_{1}\\ &\quad + (\cdots)\,x_{2}\,, \end{aligned} $$ and the coefficient of $x_{1}$ in $z_{1}$ is exactly the inner product of the first row of $\mathbf{A}$ with the first column of $\mathbf{B}.$ The same happens in every slot. So if we want a product $\mathbf{A}\mathbf{B}$ whose entries are the coefficients of the composed system — and we do, because composing substitutions is what linear models constantly require — the definition is settled for us. The matrix product below is exactly that.

(Here $\mathbf{B}=(b_{jk})$ is the $3\times2$ matrix of the first system and $\mathbf{A}=(a_{ij})$ the $2\times3$ matrix of the second.)

One entry of the product: row $1$ of $\mathbf{A}$ against column $1$ of $\mathbf{B}$ gives $c_{11}=2\cdot1+(-1)\cdot2+3\cdot1=3.$ The other three entries are the other three row–column pairs. The last line of the figure points back to the inner product of the previous section. (Small on a phone; the numbers are those of Example 12.20.)
Example 12.20

A product, shape first

Let $$ \begin{aligned} \mathbf{A}&=\begin{pmatrix} 2 & -1 & 3\\ 0 & 4 & 1\end{pmatrix}\,,\\ \mathbf{B}&=\begin{pmatrix} 1 & 0\\ 2 & -3\\ 1 & 5\end{pmatrix}\,. \end{aligned} $$ Find $\mathbf{A}\mathbf{B},$ and the order of $\mathbf{B}\mathbf{A}.$

Try it yourself first. Then open one step at a time.

Try it yourself

One row, one column, one number

Left $\mathbf{A},$ in the middle $\mathbf{B},$ right $\mathbf{A}\mathbf{B};$ under them the arithmetic for the entry being computed. The first setting is Example 12.20.

  1. Press Next entry four times. Each time one row of $\mathbf{A}$ meets one column of $\mathbf{B}$ and gives one number of $\mathbf{A}\mathbf{B}.$
  2. Press the shapes button once: the same $\mathbf{A}$ with a $2\times3$ matrix $\mathbf{B},$ $2\times3$ times $2\times3.$ Before you read the canvas, say why there is no product.
  3. Press it again for a $3\times2$ times $2\times4$ product. Predict its order, then press Fill it in and count the entries.

Guess first. Answer the next question without any arithmetic: write the two orders side by side for each product, and decide which pair has to agree and which pair is the answer.

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

$\mathbf{A}$ is $3 \times 4$ and $\mathbf{B}$ is $4 \times 3$.

Which of $\mathbf{AB}$ and $\mathbf{BA}$ exist, and what are their orders?

Shape first, arithmetic second: the inner two numbers must agree, the outer two are the order of the answer. A row times a column, $(1\times4)(4\times1),$ is $1\times1{:}$ the inner product again.

In the practice hub the question "how many columns does $\mathbf{A}\mathbf{B}$ have?" has so far been answered correctly only about half the time (few answers yet), while the same question about rows does much better. The columns come from the right-hand factor: in $(m\times n)(n\times p)$ they are its $p.$

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

Let $$ \begin{aligned} \mathbf{A}&=\begin{pmatrix} 1 & 2 & 0\\ 3 & -1 & 4\end{pmatrix}\,,\\ \mathbf{B}&=\begin{pmatrix} 2 & 1\\ 1 & 5\\ -1 & 3\end{pmatrix}\,. \end{aligned} $$ What is the entry $c_{21}$ of $\mathbf{C}=\mathbf{A}\mathbf{B}?$

6

A system is one equation

Two equations or two hundred: can a whole system be written as one equation, three characters long?

The definition pays for itself immediately.

Guess first. Before you read the Fact below, answer this: what is the product of a coefficient matrix and the column of unknowns?

Check yourself

Pick an answer before reading on. Getting it wrong is fine — that is how you find out what you believe.

$\mathbf{A}$ is the $m \times n$ coefficient matrix of a system, $\mathbf{x}$ the column of unknowns, $\mathbf{b}$ the column of right-hand sides.

What is $\mathbf{Ax}$?

Fact 12.21A system is one equation#

Let $\mathbf{A}$ be the coefficient matrix of the system (12.1), let $\mathbf{x}$ be the column vector of unknowns and $\mathbf{b}$ the column vector of constant terms. Then (12.1) says exactly $$ \mathbf{A}\mathbf{x}=\mathbf{b}\,. $$

Three equations in three unknowns become one equation, $\mathbf{A}\mathbf{x}=\mathbf{b}{:}$ the coefficients are $\mathbf{A},$ the unknowns the column $\mathbf{x},$ the right-hand sides the column $\mathbf{b}.$ (Small on a phone; the three equations are listed in the description of the image.)

An $m\times n$ system now looks like $ax=b$ from school, and the rest of the block is about how far that resemblance can be pushed: which rules of ordinary algebra survive (Lecture 13), and whether one can divide by $\mathbf{A}$ (Lecture 14).

Example

Checking a solution with one product

This example is the app's. Write the system $$ \begin{aligned} x_{1}+2x_{2}&=5\\ 3x_{1}-x_{2}&=1\\ 2x_{1}+x_{2}&=4 \end{aligned} $$ as $\mathbf{A}\mathbf{x}=\mathbf{b},$ and decide with a matrix product whether $(1,2)$ and $(2,1)$ are solutions.

Try it yourself first. Then open one step at a time.

What you should take away

  • An $m\times n$ matrix $\mathbf{A}=(a_{ij})$ has $m$ rows and $n$ columns, and $a_{ij}$ is the entry in row $i$, column $j$ — row index first, always. A matrix with one row or one column is a vector.
  • Two matrices are equal when they have the same order and agree entry by entry, so one matrix equation is $mn$ ordinary ones.
  • In a system of $m$ equations in $n$ unknowns, $a_{ij}$ is the coefficient of variable $x_{j}$ in equation $i$; a solution is an ordered list, and the system is consistent if one exists.
  • Addition and scalar multiplication act entry by entry and need matrices of the same order. They obey the rules of ordinary algebra.
  • The inner product $\mathbf{a}\cdot\mathbf{b}=\sum_{j}a_{j}b_{j}$ needs equal dimensions and returns a number. Prices $\cdot$ quantities $=$ money is the example to keep.
  • $\mathbf{A}\mathbf{B}$ has $(i,k)$ entry equal to the inner product of row $i$ of $\mathbf{A}$ with column $k$ of $\mathbf{B}$. It exists only when the columns of $\mathbf{A}$ match the rows of $\mathbf{B}$, and then $(m\times n)(n\times p)=m\times p$.
  • That rule is not arbitrary: it is exactly what makes substituting one linear system into another come out right. Its immediate reward is that any system becomes the single equation $\mathbf{A}\mathbf{x}=\mathbf{b}$.

Think further

Questions without computation. Think on your own or with a classmate before opening the thought.

  1. Discussion question 1 — three operations, three verdicts

    $\mathbf{A}$ is $3\times5$ and $\mathbf{B}$ is $5\times3$. Which of $\mathbf{A}+\mathbf{B}$, $\mathbf{A}\mathbf{B}$, $\mathbf{B}\mathbf{A}$ are defined, and what are their orders?

    One way to think about it

    $\mathbf{A}+\mathbf{B}$ is not defined: the orders $3\times5$ and $5\times3$ differ (Watch out 12.9), although both have fifteen entries. Both products exist, because in each the inner two numbers agree: $$ \begin{aligned} (3\times5)(5\times3)&=3\times3\,,\\ (5\times3)(3\times5)&=5\times5\,. \end{aligned} $$ So $\mathbf{A}\mathbf{B}$ is $3\times3$ and $\mathbf{B}\mathbf{A}$ is $5\times5:$ the same two matrices, and products of different sizes.

  2. Discussion question 2 — can a·a be negative?

    $\mathbf{a}=(1,-2,3)$ and $\mathbf{b}=(-3,2,5)$. Compute $\mathbf{a}\cdot\mathbf{b}$, and then $\mathbf{a}\cdot\mathbf{a}$. Can the second ever be negative?

    One way to think about it

    $$ \begin{aligned} \mathbf{a}\cdot\mathbf{b}&=-3-4+15=8\,,\\ \mathbf{a}\cdot\mathbf{a}&=1+4+9=14\,. \end{aligned} $$ The second can never be negative. $\mathbf{a}\cdot\mathbf{a}$ is the sum of the squares of the components, and a square is never negative; it is $0$ only for the zero vector. That is rule (d) of Fact 12.16. An inner product of two different vectors can be negative, of course: $(1,0)\cdot(-1,0)=-1.$

  3. Discussion question 3 — a system multiplied out

    Write the system $2x_{1}-x_{2}=5$, $x_{1}+3x_{2}=1$ in the form $\mathbf{A}\mathbf{x}=\mathbf{b}$, and check by multiplying out that you recover the two equations.

    One way to think about it

    $$ \begin{aligned} \mathbf{A}&=\begin{pmatrix} 2 & -1\\ 1 & 3\end{pmatrix}\,,\\ \mathbf{x}&=\begin{pmatrix} x_{1}\\ x_{2}\end{pmatrix}\,,\quad \mathbf{b}=\begin{pmatrix} 5\\ 1\end{pmatrix}\,. \end{aligned} $$ Multiplying out, row by row, $$ \mathbf{A}\mathbf{x}=\begin{pmatrix} 2x_{1}-x_{2}\\ x_{1}+3x_{2}\end{pmatrix}\,, $$ and this column equals $\mathbf{b}$ exactly when $2x_{1}-x_{2}=5$ and $x_{1}+3x_{2}=1$ (Definition 12.2): the two equations, and nothing else (Fact 12.21).

  4. Discussion question 4 — must AB equal BA?

    $\mathbf{A}$ is $4\times4$ and $\mathbf{B}$ is $4\times4$. Must $\mathbf{A}\mathbf{B}=\mathbf{B}\mathbf{A}$?

    (A) yes, both products exist and have the same order;

    (B) yes, because multiplication of numbers commutes;

    (C) no — both exist and have the same order, and that is no reason for them to be equal;

    (D) only if $\mathbf{A}$ and $\mathbf{B}$ are diagonal.

    One way to think about it

    (C). (A) confuses existing with being equal: the orders decide only whether a product exists. (B) forgets what an entry of a product is: the entry $(i,k)$ of $\mathbf{A}\mathbf{B}$ uses row $i$ of $\mathbf{A}$ and column $k$ of $\mathbf{B},$ and of $\mathbf{B}\mathbf{A}$ row $i$ of $\mathbf{B}$ and column $k$ of $\mathbf{A}$ — different numbers, so the commutativity of numbers does not help. (D) is too strong: every matrix commutes with itself, $\mathbf{A}\mathbf{A}=\mathbf{A}\mathbf{A},$ diagonal or not.

    An example (the app's), in the $2\times2$ case: $$ \begin{aligned} \begin{pmatrix} 1 & 1\\ 0 & 1\end{pmatrix} \begin{pmatrix} 1 & 0\\ 1 & 1\end{pmatrix} &=\begin{pmatrix} 2 & 1\\ 1 & 1\end{pmatrix}\,,\\ \begin{pmatrix} 1 & 0\\ 1 & 1\end{pmatrix} \begin{pmatrix} 1 & 1\\ 0 & 1\end{pmatrix} &=\begin{pmatrix} 1 & 1\\ 1 & 2\end{pmatrix}\,. \end{aligned} $$ Put these two matrices in the top left corner of two $4\times4$ matrices, with zeros everywhere else, and the two products differ in the same corner.