Matrices in Depth

Theory, properties, interactive calculators, and GNU Octave lab

1. What is a matrix

A matrix is a rectangular array of numbers arranged in rows and columns. We write an $m imes n$ matrix $A$ as:

$$A = egin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \ a_{21} & a_{22} & \cdots & a_{2n} \ dots & dots & \ddots & dots \ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix}$$

where $a_{ij}$ is the entry in row $i$, column $j$. Matrices encode linear transformations, systems of equations, data tables, graphs, and more.

Core vocabulary

2. Important types

TypeDefinitionNotation
ZeroAll entries 0$0_{m imes n}$
Identity1s on diagonal, 0s elsewhere$I_n$
DiagonalNonzero only on $a_{ii}$$\operatorname{diag}(d_1,\dots,d_n)$
Upper triangular$a_{ij}=0$ for $i>j$
Lower triangular$a_{ij}=0$ for $i
Symmetric$A^T = A$
Skew-symmetric$A^T = -A$
Orthogonal$Q^T Q = I$columns are orthonormal
Idempotent$A^2 = A$projectors
InvertibleExists $A^{-1}$ with $AA^{-1}=I$$\det A eq 0$

3. Operations and properties

Addition and scalar multiplication

$(A+B)_{ij}=a_{ij}+b_{ij}$, $(cA)_{ij}=c a_{ij}$. Same size required for addition.

Properties: commutative $A+B=B+A$, associative, distributive $c(A+B)=cA+cB$.

Matrix multiplication

For $A$ ($m imes k$) and $B$ ($k imes n$): $(AB)_{ij} = \sum_{t=1}^k a_{it} b_{tj}$.

Not commutative in general: $AB eq BA$. Associative: $(AB)C = A(BC)$. Distributive over addition.

Transpose

$(A^T)_{ij}=a_{ji}$. Properties: $(AB)^T = B^T A^T$, $(A^T)^T = A$.

Trace

$\operatorname{tr}(A)=\sum_i a_{ii}$. $\operatorname{tr}(AB)=\operatorname{tr}(BA)$.

Interactive: addition

+
=

Interactive: multiplication (2x2)

×
=

4. Determinant, inverse, rank

Determinant measures volume scaling. For 2x2: $\detegin{bmatrix}a&b\c&d\end{bmatrix}=ad-bc$.

For 3x3 use rule of Sarrus or cofactor expansion.

Inverse: $A^{-1}$ exists iff $\det A eq 0$. For 2x2: $A^{-1} = rac1{ad-bc}egin{bmatrix}d&-b\-c&a\end{bmatrix}$.

Rank: dimension of column space. $\operatorname{rank}(A) \le \min(m,n)$. Full rank means invertible for square matrices.

Interactive: determinant and inverse (2x2)


5. Eigenvalues and eigenvectors

$Av = \lambda v$ for nonzero $v$. $\lambda$ is eigenvalue, $v$ eigenvector.

Characteristic polynomial: $p(\lambda)=\det(A-\lambda I)=0$.

Diagonalization: if $A$ has $n$ independent eigenvectors, $A = PDP^{-1}$ with $D=\operatorname{diag}(\lambda_i)$. Symmetric real matrices are orthogonally diagonalizable.

6. Decompositions

7. Solving linear systems

System $Ax=b$. If $A$ invertible: $x = A^{-1}b$. In practice use Gaussian elimination or $x = A ackslash b$ in Octave.

Consistency: solution exists iff $\operatorname{rank}(A)=\operatorname{rank}([A|b])$. Unique iff rank equals $n$.

8. GNU Octave lab

Octave syntax mirrors MATLAB. Copy these into Octave.

% Basics
A = [1 2; 3 4]
B = [5 6; 7 8]
A + B
2 * A
A * B
A'          % transpose

% Determinant, inverse, rank, trace
det(A)
inv(A)
rank(A)
trace(A)

% Solve Ax = b
b = [5; 11]
x = A \ b   % preferred over inv(A)*b

% Eigen
[V, D] = eig(A)   % V columns are eigenvectors, D diagonal eigenvalues

% LU decomposition with partial pivoting
[L, U, P] = lu(A)
P*A - L*U   % should be near zero

% QR
[Q, R] = qr(A)
Q'*Q        % identity check

% SVD
[U, S, V] = svd(A)
U*S*V' - A  % reconstruction error

% Create special matrices
I = eye(3)
Z = zeros(2,4)
O = ones(3)
D = diag([2, -1, 4])
R = rand(3)   % uniform random

% Symmetric positive definite test
M = A'*A
eig(M)   % all >0

Octave tips

9. Why matrices matter

10. Practice problems

  1. Compute $AB$ for $A=egin{bmatrix}1&2&3\0&1&4\end{bmatrix}$, $B=egin{bmatrix}1&0\-1&2\3&1\end{bmatrix}$.
  2. Find $\det$ and $A^{-1}$ for $A=egin{bmatrix}2&5\1&3\end{bmatrix}$.
  3. Show that if $Q$ is orthogonal, $\|Qx\|=\|x\|$.
  4. In Octave, generate random $4 imes4$ $A$, compute its SVD, verify reconstruction error norm is $<10^{-12}$.
  5. Diagonalize $A=egin{bmatrix}4&1\2&3\end{bmatrix}$ using eig.