A matrix is a rectangular array of numbers arranged in rows and columns. Matrices provide a powerful way to organize data and solve systems of linear equations.
An \(m \times n\) matrix (read as “\(m\) by \(n\)”) has \(m\) rows and \(n\) columns. We denote the element in the \(i\)-th row and \(j\)-th column as \(a_{ij}\).
\[ A = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix} \]
Addition is performed element-wise and is only defined for matrices of the same size.
Addition: If \(A = [a_{ij}]\) and \(B = [b_{ij}]\), then \(A + B = [a_{ij} + b_{ij}]\). Scalar Multiplication: If \(k\) is a scalar, then \(kA = [k \cdot a_{ij}]\).
The product \(AB\) is defined only if the number of columns in \(A\) equals the number of rows in \(B\). If \(A\) is \(m \times n\) and \(B\) is \(n \times p\), the resulting matrix \(C = AB\) is \(m \times p\).
The element \(c_{ij}\) is calculated as: \[c_{ij} = \sum_{k=1}^{n} a_{ik}b_{kj}\]
Table 1: Compatibility of Matrix Operations
| Operation | Requirement | Resulting Dimension |
|---|---|---|
| Addition (\(A+B\)) | \(A\) and \(B\) must be same size (\(m \times n\)) | \(m \times n\) |
| Multiplication (\(AB\)) | Col(\(A\)) = Row(\(B\)) | Row(\(A\)) \(\times\) Col(\(B\)) |
| Transpose (\(A^T\)) | None | \(n \times m\) |
In computer science, a grayscale digital image is essentially a matrix where each element \(a_{ij}\) represents a pixel’s brightness (0 to 255).
Matrix multiplication can be used to rotate, scale, or shear images. Below, we use a shear matrix \(S\) to transform a set of points:
\[ S = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} \]
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Figure 1: Geometric Transformation of a Square using Matrix Multiplication
In the Hill Cipher, matrices are used to encrypt text. Letters are converted to numbers (A=0, B=1, etc.), grouped into vectors, and multiplied by an invertible encoding matrix \(E\).
If the message vector is \(P\) (Plaintext), the encrypted vector \(C\) (Ciphertext) is: \[C = E \cdot P \pmod{26}\]
1. Basic Computation Given \(A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}\) and \(B = \begin{bmatrix} 0 & 5 \\ -1 & 2 \end{bmatrix}\), compute: a) \(A + B\) b) \(3A\) c) \(AB\)
2. Transpose Properties Show that for the matrices in Exercise 1, \((AB)^T = B^T A^T\).
3. Application: Inventory Tracking A store has two locations. The inventory for three products is represented by matrices \(L_1\) and \(L_2\): \(L_1 = \begin{bmatrix} 10 & 20 & 30 \end{bmatrix}\) (Items in Location 1) \(L_2 = \begin{bmatrix} 15 & 25 & 10 \end{bmatrix}\) (Items in Location 2) Calculate the total inventory matrix \(T = L_1 + L_2\).
4. Challenge Construct a \(2 \times 2\) matrix \(A\) (other than the Identity or Zero matrix) such that \(A^2 = A\). (This is called an idempotent matrix).
End of Chapter 2 ```