This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Vector and matrix norms




n = norm(v) returns the 2-norm or Euclidean norm of vector v.


n = norm(v,p) returns the vector norm defined by sum(abs(v)^p)^(1/p), where p is any positive real value, Inf, or -Inf.

  • If p is Inf, then n = max(abs(v)).

  • If p is -Inf, then n = min(abs(v)).


n = norm(X) returns the 2-norm or maximum singular value of matrix X.


n = norm(X,p) returns the p-norm of matrix X, where p is 1, 2, or Inf.


n = norm(X,'fro') returns the Frobenius norm, sqrt(sum(diag(X'*X))).


collapse all

1- and 2- Norm of Vector

Calculate the 2-norm of a vector corresponding to the point (-2,3,-1) in 3-D space. The 2-norm is equal to the Euclidean length of the vector.

X = [-2 3 -1];
n = norm(X)
n =


Calculate the 1-norm of the vector, which is the sum of the element magnitudes.

n = norm(X,1)
n =


2-Norm of Matrix

Calculate the 2-norm of a matrix, which is the largest singular value.

X = [2 0 1;-1 1 0;-3 3 0];
n = norm(X)
n =


Frobenius Norm of Sparse Matrix

Use 'fro' to calculate the Frobenius norm of a sparse matrix, which calculates the 2-norm of the column vector, S(:).

S = sparse(1:25,1:25,1);
n = norm(S,'fro')
n =


Input Arguments

collapse all

v — Input vectorvector

Input vector.

Data Types: single | double
Complex Number Support: Yes

X — Input matrixmatrix

Input matrix. Use norm(X,'fro') when X is sparse.

Data Types: single | double
Complex Number Support: Yes

p — Norm type2 (default) | positive integer scalar | Inf | -Inf

Norm type, specified as 2 (default), a different positive integer scalar, Inf, or -Inf. The valid values of p and what they return depend on whether the first input to norm is a matrix or vector, as shown in the table.

    Note:   This table does not reflect the actual algorithms used in calculations.

Positive, real-valued numeric psum(abs(X).^p)^(1/p)

Output Arguments

collapse all

n — Matrix or vector normscalar

Matrix or vector norm, returned as a scalar. The norm gives a measure of the magnitude of the elements. By convention, norm returns NaN if the input contains NaN values.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?