TExcelTAD
Home › Numerical Methods › Vector and Matrix Norms

Vector and Matrix Norms

To say that a computed solution is "close" to the true one, or that an error is "small", we need to measure the size of vectors and matrices. Norms do this. This lesson defines the common vector norms, the matrix norms they induce, and the inequalities used in every error bound for linear systems.

Vector norms

A norm ∥⋅∥\lVert\cdot\rVert satisfies ∥x∥≥0\lVert\mathbf{x}\rVert \ge 0 with equality only for 0\mathbf{0}, ∥αx∥=∣α∣ ∥x∥\lVert\alpha\mathbf{x}\rVert = \lvert\alpha\rvert\,\lVert\mathbf{x}\rVert, and the triangle inequality ∥x+y∥≤∥x∥+∥y∥\lVert\mathbf{x} + \mathbf{y}\rVert \le \lVert\mathbf{x}\rVert + \lVert\mathbf{y}\rVert. The three standard ones:

∥x∥1=∑i∣xi∣,∥x∥2=∑ixi2,∥x∥∞=max⁡i∣xi∣.\lVert\mathbf{x}\rVert_1 = \sum_i\lvert x_i\rvert, \qquad \lVert\mathbf{x}\rVert_2 = \sqrt{\sum_i x_i^2}, \qquad \lVert\mathbf{x}\rVert_\infty = \max_i\lvert x_i\rvert.

In Rn\mathbb{R}^n all norms are equivalent: for example ∥x∥∞≤∥x∥2≤n ∥x∥∞\lVert\mathbf{x}\rVert_\infty \le \lVert\mathbf{x}\rVert_2 \le \sqrt{n}\,\lVert\mathbf{x}\rVert_\infty. They differ by at most a factor depending on nn, so "converges in one norm" means "converges in all".

python · try it yourself
import numpy as np

x = np.array([3.0, -4.0, 1.0, 0.0])
for p in (1, 2, np.inf):
    print(f"||x||_{p} = {np.linalg.norm(x, p):.6f}")
print("inf <= 2 <= sqrt(n) inf:", np.linalg.norm(x, np.inf) <= np.linalg.norm(x) <= 2 * np.linalg.norm(x, np.inf))
||x||_1 = 8.000000
||x||_2 = 5.099020
||x||_inf = 4.000000
inf <= 2 <= sqrt(n) inf: True

Induced matrix norms

The norm of a matrix induced by a vector norm is the largest stretching factor:

∥A∥=max⁡x≠0∥Ax∥∥x∥.\lVert A\rVert = \max_{\mathbf{x} \ne \mathbf{0}}\frac{\lVert A\mathbf{x}\rVert}{\lVert\mathbf{x}\rVert}.

It follows immediately that ∥Ax∥≤∥A∥ ∥x∥\lVert A\mathbf{x}\rVert \le \lVert A\rVert\,\lVert\mathbf{x}\rVert and ∥AB∥≤∥A∥ ∥B∥\lVert AB\rVert \le \lVert A\rVert\,\lVert B\rVert. For the three vector norms there are explicit formulas:

Norm Formula
∥A∥1\lVert A\rVert_1 maximum absolute column sum
∥A∥∞\lVert A\rVert_\infty maximum absolute row sum
∥A∥2\lVert A\rVert_2 largest singular value σ1\sigma_1 = λmax⁡(ATA)\sqrt{\lambda_{\max}(A^TA)}

The Frobenius norm ∥A∥F=∑ijaij2\lVert A\rVert_F = \sqrt{\sum_{ij}a_{ij}^2} is not induced by a vector norm but is easy to compute and satisfies ∥A∥2≤∥A∥F\lVert A\rVert_2 \le \lVert A\rVert_F.

python · try it yourself
import numpy as np

A = np.array([[1.0, -2.0], [3.0, 4.0]])
print("1-norm  :", np.linalg.norm(A, 1), "= max column sum", np.max(np.sum(np.abs(A), axis=0)))
print("inf-norm:", np.linalg.norm(A, np.inf), "= max row sum", np.max(np.sum(np.abs(A), axis=1)))
print(f"2-norm  : {np.linalg.norm(A, 2):.6f} = sigma_1 {np.linalg.svd(A, compute_uv=False)[0]:.6f}")
print(f"Frobenius: {np.linalg.norm(A, 'fro'):.6f}")

rng = np.random.default_rng(8)
X = rng.normal(size=(2, 100_000))
ratios = np.linalg.norm(A @ X, axis=0) / np.linalg.norm(X, axis=0)
print(f"largest stretch among 100000 random vectors: {ratios.max():.6f}")
1-norm  : 6.0 = max column sum 6.0
inf-norm: 7.0 = max row sum 7.0
2-norm  : 5.116673 = sigma_1 5.116673
Frobenius: 5.477226
largest stretch among 100000 random vectors: 5.116673

Why norms matter here

The error bounds in the next lesson have the form

∥δx∥∥x∥≤κ(A)∥δb∥∥b∥,κ(A)=∥A∥ ∥A−1∥,\frac{\lVert\delta\mathbf{x}\rVert}{\lVert\mathbf{x}\rVert} \le \kappa(A)\frac{\lVert\delta\mathbf{b}\rVert}{\lVert\mathbf{b}\rVert}, \qquad \kappa(A) = \lVert A\rVert\,\lVert A^{-1}\rVert,

which only makes sense once vector and matrix sizes are measured consistently (Conditioning of Linear Systems).

In software

  • np.linalg.norm(x, ord) handles vectors and matrices; axis= computes norms of rows or columns at once.
  • Machine learning uses ∥⋅∥1\lVert\cdot\rVert_1 (lasso, sparsity) and ∥⋅∥22\lVert\cdot\rVert_2^2 (ridge, weight decay) as penalties, and spectral norms for Lipschitz constraints in GANs (Norms).

Exercises

Exercise 1: Vector norms

Compute the 1-, 2- and ∞\infty-norms of (1,−2,2)(1, -2, 2).

Answer

5, 3, 2.

Solution

1+2+2=51 + 2 + 2 = 5; 1+4+4=3\sqrt{1 + 4 + 4} = 3; max⁡=2\max = 2.

Exercise 2: Matrix norms by hand

Find ∥A∥1\lVert A\rVert_1 and ∥A∥∞\lVert A\rVert_\infty for A=(2−105)A = \begin{pmatrix} 2 & -1 \\ 0 & 5\end{pmatrix}.

Answer

∥A∥1=6\lVert A\rVert_1 = 6, ∥A∥∞=5\lVert A\rVert_\infty = 5.

Solution

Column sums 22 and 66; row sums 33 and 55.

Exercise 3: The worst vector (code)

The 2-norm is attained at the first right singular vector v1\mathbf{v}_1. Verify that ∥Av1∥2=σ1\lVert A\mathbf{v}_1\rVert_2 = \sigma_1 for A=(1−234)A = \begin{pmatrix} 1 & -2 \\ 3 & 4\end{pmatrix}.

Answer

Both equal 5.1166735.116673 (rounded).

Solution
python · try it yourself
import numpy as np
A = np.array([[1.0, -2.0], [3.0, 4.0]])
U, s, Vt = np.linalg.svd(A)
v1 = Vt[0]
print(round(float(np.linalg.norm(A @ v1)), 6), round(float(s[0]), 6))
5.116673 5.116673

Test yourself

The matrix ∞\infty-norm equals…

  1. the largest column sum of absolute values
  2. the largest row sum of absolute values
  3. the largest singular value
  4. the largest entry

The matrix 2-norm equals…

  1. the largest eigenvalue of AA
  2. the largest singular value of AA
  3. the Frobenius norm
  4. the determinant

Which inequality holds for any induced norm?

  1. ∥AB∥≥∥A∥ ∥B∥\lVert AB\rVert \ge \lVert A\rVert\,\lVert B\rVert
  2. ∥AB∥≤∥A∥ ∥B∥\lVert AB\rVert \le \lVert A\rVert\,\lVert B\rVert
  3. ∥A+B∥=∥A∥+∥B∥\lVert A + B\rVert = \lVert A\rVert + \lVert B\rVert
  4. ∥A∥=∣det⁡A∣\lVert A\rVert = \lvert\det A\rvert