This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Vector and matrix norms


n = norm(v)
n = norm(v,p)
n = norm(X)
n = norm(X,p)
n = norm(X,'fro')



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


n = norm(v,p) returns the generalized vector p-norm.


n = norm(X) returns the 2-norm or maximum singular value of matrix X, which is approximately max(svd(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 of matrix X.


collapse all

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 = 3.7417

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

n = norm(X,1)
n = 6

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 = 4.7234

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 = 5

Input Arguments

collapse all

Input vector.

Data Types: single | double
Complex Number Support: Yes

Input matrix.

Data Types: single | double
Complex Number Support: Yes

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.


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

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

Output Arguments

collapse all

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.

More About

collapse all

Euclidean Norm

The Euclidean norm (or 2-norm) of a vector v that has N elements is defined by


General Vector Norm

The general definition for the vector p-norm of a vector v that has N elements is


where p is any positive real value, Inf, or -Inf.

  • If p = Inf, then v=maxi(|v(i)|).

  • If p = -Inf, then v=mini(|v(i)|).

Maximum Absolute Column Sum

The maximum absolute column sum of an m-by-n matrix X (with m,n >= 2) is defined by


Maximum Absolute Row Sum

The maximum absolute row sum of an m-by-n matrix X (with m,n >= 2) is defined by


Frobenius Norm

The Frobenius norm of an m-by-n matrix X (with m,n >= 2) is defined by


Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?