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 \\:
The last row needs no \\. Spaces and line breaks inside are ignored, so you can lay the source out like the matrix itself:
\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.
Column vectors
A column vector is a matrix with one column: no &, just \\ between the rows.
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.
A transpose and an inverse are powers: A^T gives and A^{-1} gives .
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.
cases also writes a system of equations: one equation on each line.
Practise
&between the entries,\\between the rows.\begin{pmatrix} a & b \\ c & d \end{pmatrix}bmatrixfor square brackets; three rows of three.\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\detprints det upright, then the matrix.\det \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} = -2One column: no
&.\begin{pmatrix} x \\ y \end{pmatrix}The power needs braces:
A^{-1}.A^{-1} = \frac{1}{ad - bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}\cdots,\vdotsand\ddotsfill the gaps.\begin{pmatrix} a_{11} & \cdots & a_{1n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \cdots & a_{mn} \end{pmatrix}In
cases: value,&, condition,\\.f(x) = \begin{cases} 1 & x > 0 \\ 0 & x = 0 \\ -1 & x < 0 \end{cases}One equation per line,
\\between them.\begin{cases} x + y = 3 \\ x - y = 1 \end{cases}
In short
&moves to the next column,\\to the next row.pmatrix,bmatrix,Bmatrix,vmatrixandVmatrixchoose the brackets.\cdots,\vdotsand\ddotsfill large matrices;casesbuilds functions in parts and systems of equations.
Next, in lesson 10: lining up equations over several lines.