LatexNotes

Lesson 9 of 12

Matrices and cases

Grids built from & and \\: matrices, determinants, column vectors and functions in several parts. About twelve minutes.

A matrix is a grid, and LaTeX builds grids from two characters: & moves to the next column and \\ starts the next row. The same two build functions defined in several parts.

A first matrix

A matrix goes between \begin{pmatrix} and \end{pmatrix}. Inside, separate the entries in a row with & and end each row with \\:

(1234)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}

The last row needs no \\. Spaces and line breaks inside are ignored, so you can lay the source out like the matrix itself:

LaTeX
\begin{pmatrix}
  1 & 2 \\
  3 & 4
\end{pmatrix}

The brackets round it

The first letters of the name choose the brackets:

  • matrix: none.
  • pmatrix: round brackets, (  )( \; ).
  • bmatrix: square brackets, [  ][ \; ].
  • Bmatrix: curly braces, {  }\{ \; \}.
  • vmatrix: straight bars, for a determinant.
  • Vmatrix: double bars, for a norm.
∣abcd∣=ad−bc\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc

Column vectors

A column vector is a matrix with one column: no &, just \\ between the rows.

v=(xyz)\mathbf{v} = \begin{pmatrix} x \\ y \\ z \end{pmatrix}

Large matrices

For a matrix of any size, fill the gaps with dots: \cdots along a row, \vdots down a column, and \ddots along the diagonal.

(a11⋯a1n⋮⋱⋮am1⋯amn)\begin{pmatrix} a_{11} & \cdots & a_{1n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \cdots & a_{mn} \end{pmatrix}

A transpose and an inverse are powers: A^T gives ATA^T and A^{-1} gives A−1A^{-1}.

Functions in several parts

cases makes the big brace of a function defined piece by piece. Each line is the value, then &, then the condition, and \\ ends the line. \text{...} writes words, as you saw in lesson 2.

∣x∣={xif x≥0−xif x<0|x| = \begin{cases} x & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}

cases also writes a system of equations: one equation on each line.

{x+y=3x−y=1\begin{cases} x + y = 3 \\ x - y = 1 \end{cases}

Practise

  1. (abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix}

  2. [100010001]\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

  3. det⁡(1234)=−2\det \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} = -2

  4. (xy)\begin{pmatrix} x \\ y \end{pmatrix}

  5. A−1=1ad−bc(d−b−ca)A^{-1} = \frac{1}{ad - bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}

  6. (a11⋯a1n⋮⋱⋮am1⋯amn)\begin{pmatrix} a_{11} & \cdots & a_{1n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \cdots & a_{mn} \end{pmatrix}

  7. f(x)={1x>00x=0−1x<0f(x) = \begin{cases} 1 & x > 0 \\ 0 & x = 0 \\ -1 & x < 0 \end{cases}

  8. {x+y=3x−y=1\begin{cases} x + y = 3 \\ x - y = 1 \end{cases}

In short

  • & moves to the next column, \\ to the next row.
  • pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix choose the brackets.
  • \cdots, \vdots and \ddots fill large matrices; cases builds functions in parts and systems of equations.

Next, in lesson 10: lining up equations over several lines.

Would you rather write it by hand?

LatexNotes turns a photo or PDF of your handwritten maths into LaTeX like this. Free to try, no sign-up.

Convert your handwriting to LaTeX →