5  Matrix

Not the movie by Keanu Reaves

The french can be creative when translating movie titles. Home Alone in french was “Maman j’ai raté l’avion”. But sometimes, they kept the english title like in Matrix, the movie by Keanue Reaves. With the popularity of the series, when talking about matrix, Malagasy first thought is the movie. The frustration is familiar to Malagasy people when people first think about the animated series, lions and zebra, before their island.

Matrix, a mathematical object, existed well before the movie series. A matrix is rectangular way of storing numbers.

Rabe, Rakoto, Sanda, and Dora when to market.

This information could be arranged in a matrix, each row represents a purchaser, and a column a fruit \[ \begin{pmatrix} 6 & 3 & 0.5 \\ 3 & 1 & 0 \\ 0 & 10 & 0 \\ 1 & 0 & 2 \end{pmatrix} \tag{5.1}\]

Alternatively, the data could be arranged by putting the purchaser on the column and the fruit on the row. \[ \begin{pmatrix} 6 & 3 & 0 & 1 \\ 3 & 1 & 10 & 0 \\ 0.5 & 0 & 0 & 2 \end{pmatrix} \]

These two rectangles contains the same amount of information (provided the meaning of the rows and columns are clear). The conversion from the first matrix to the second one is called transposing.

Formal

An \(m \times n\) matrix is a rectangular array of numbers having \(m\) rows and \(n\) columns. It is denoted as:

\[ A = \begin{pmatrix} a_{11} & a_{12} & \dots & a_{1n} \\ a_{21} & a_{22} & \dots & a_{2n} \\ \vdots & \vdots & & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{pmatrix} \tag{5.2}\]

where the numbers \(a_{\{i,j\}}\) denotes the entry in the \(i^{th}\) row and \(j^{th}\) column of A. The domain of the row index \(i\) is \(\{1,2 \ldots ,m \}\) and the domain of the column index \(j\) is \(\{1,2,\dots ,n\}\).

In mathematics, a vector is special case of matrix as \(n \times 1\) or sometimes \(1 \times n\). It can always be transposed and the transpose notation is $ $ so

\[ V^\top = \begin{pmatrix} a_1 & a_2 & \cdots a_n \end{pmatrix}^\top = \begin{pmatrix} a_1 \\ a_2 \\ \vdots \\ a_n \end{pmatrix} \]

Examples

  • A square matrix is a matrix with the same number of rows and columns.

\[ \begin{pmatrix} 6 & 3 & 0 \\ 3 & 1 & 10 \\ 0.5 & 0 & 0 \end{pmatrix} \]

  • A diagonal matrix has all off-diagonal elements equal to 0, often denoted diag(). \[ \text{diag}(a, b, c) = \begin{pmatrix} a & 0 & 0 \\ 0 & b & 0 \\ 0 & 0 & c \end{pmatrix} \]

  • A matrix is symmetric when its entries are identical across the main diagonal, i.e., \(a_{i,j} = a_{j,i}\).

\[ \begin{pmatrix} a & 1 & x \\ 1 & b & -1 \\ x & -1 & c \end{pmatrix} \]

Tips and warning

  • A community matrix for an ecologist is a matrix where each row represents a site and each column represents a species (containing presence-absence or abundance data).

  • A design matrix is a matrix where each row represents a site and each column represents a variable (altitude, temperature, etc.).

  • A distance matrix is a square and symmetric matrix computed from the community matrix. Each entry represents a pairwise distance between two sites (difference in species composition) or between two species (difference in species distribution). Because the distance between site A and site B is the same as the distance between site B and site A, the matrix is symmetric.

  • A matrix is more than a rectangle storing data; it is the foundation of linear algebra…and sometimes has magical properties. Perhaps in future chapters.

  • A data frame (Chapter 38) is also a rectangular object mostly used in data science. The columns can be of different types (numbers, text, etc.). There is no mathematical equivalent of a data frame.

5.0.0.1 Semantic/Terminology/Notation

  • The entry in the \(i^{\text{th}}\) row and \(j^{\text{th}}\) column is also called the \((i, j)^{\text{th}}\) element of the matrix. [Note: Clarified indexing terminology; \(i\) and \(j\) refer to the row and column indices respectively, rather than two separate elements.]

  • For more succinct notation, the curly brackets and comma can be omitted, using \(a_{ij}\) instead of \(a_{i,j}\) or \(a_{\{i, j\}}\) as in Equation 5.2.