norm

Norm of a vector or matrix.

Category: Mathematics > Linear Algebra

Syntax

n = norm(v)

Euclidean length of a vector, or the 2-norm of a matrix (largest singular value).

n = norm(X, p)

The p-norm: 1, 2, Inf, 'fro', and any p >= 1 for vectors.

Description

For a vector, the 1-norm is the sum of absolute values, the 2-norm is the usual length, and the infinity norm is the largest absolute value. For a matrix, the 1-norm is the largest column sum of absolute values, the infinity norm is the largest row sum, the 2-norm is the largest singular value, and the Frobenius norm is the square root of the sum of squares of all entries.

Note that for a matrix norm(A) is the 2-norm and is not the same as the Frobenius norm. The 2-norm needs a singular value computation; for large matrices normest is cheaper.

Input arguments

X
Vector or matrix.
p
Norm type, default 2. 'fro' is the Frobenius norm.

Output arguments

n
Non-negative scalar. The norm of an empty array is 0.

Example

Vector and matrix norms

v = [3 4];
norm(v)
norm(v, 1)
norm(v, Inf)
A = [1 2; 3 4];
norm(A)
norm(A, 'fro')
norm(A, 1)
Output
ans = 5
ans = 7
ans = 4
ans = 5.4650
ans = 5.4772
ans = 6

See also

normest cond vecnorm pagenorm svd