Language Reference

NORM Function

NORM (x, <, method> ) ;

This function is supported by the IML procedure and the iml action.

The NORM function computes the vector or matrix norm of x. The norm depends on the metric specified by the method argument. The arguments are as follows:

x

specifies a numeric vector with n elements or an n times p numeric matrix.

method

is an optional argument that specifies the method used to specify the norm. The method argument is either a numeric value, methodgreater than or equals 1, or a case-insensitive character value. The valid options are given in the following sections.

Methods for Vector Norms

If x is a vector, then a vector norm is computed. The following are valid values of the method argument:

"L1"

specifies that the function compute the 1-norm: StartMetric x EndMetric Subscript 1 Baseline equals normal upper Sigma Subscript k Baseline StartAbsoluteValue x Subscript k Baseline EndAbsoluteValue. An equivalent alias is "CityBlock" or "Manhattan".

"L2"

specifies that the function compute the Euclidean 2-norm: StartMetric x EndMetric Subscript 2 Baseline equals StartRoot left parenthesis EndRoot x prime x right parenthesis equals left parenthesis normal upper Sigma Subscript k Baseline StartAbsoluteValue x Subscript k Baseline EndAbsoluteValue squared right parenthesis Superscript 1 divided by 2. This is the default value. An equivalent alias is "Euclidean" or "Frobenius".

"LInf"

specifies that the function compute the normal infinity-norm: StartMetric x EndMetric Subscript normal infinity Baseline equals max Underscript k Endscripts StartAbsoluteValue x Subscript k Baseline EndAbsoluteValue.

An equivalent alias is "Chebyshev".

p

is a numeric value, p greater than or equals 1, that specifies the p-norm: StartMetric x EndMetric Subscript p Baseline equals left parenthesis normal upper Sigma Subscript k Baseline StartAbsoluteValue x Subscript k Baseline EndAbsoluteValue Superscript p Baseline right parenthesis Superscript 1 divided by p, p greater than or equals 1.

Methods for Matrix Norms

For an n times p matrix A such that n greater than 1 and p greater than 1, the method argument has the following valid values:

"Frobenius"

specifies the Frobenius norm: StartMetric upper A EndMetric Subscript upper F Baseline equals left parenthesis normal upper Sigma Subscript i equals 1 Superscript n Baseline normal upper Sigma Subscript j equals 1 Superscript p Baseline StartAbsoluteValue a Subscript i j Baseline EndAbsoluteValue squared right parenthesis Superscript 1 divided by 2. This is the default value.

"L1"

specifies the matrix 1-norm: StartMetric upper A EndMetric Subscript 1 Baseline equals max Underscript 1 less than or equals j less than or equals p Endscripts normal upper Sigma Subscript i equals 1 Superscript n Baseline StartAbsoluteValue a Subscript i j Baseline EndAbsoluteValue. This norm computes the maximum of the absolute column sums.

"L2"

specifies the matrix 2-norm, which is equivalent to the square root of the largest eigenvalue of the upper A prime upper A matrix. This quantity can be expensive to compute because the function internally computes eigenvalues.

"LInf"

specifies the normal infinity-norm: StartMetric upper A EndMetric Subscript normal infinity Baseline equals max Underscript 1 less than or equals i less than or equals n Endscripts normal upper Sigma Subscript j equals 1 Superscript p Baseline StartAbsoluteValue a Subscript i j Baseline EndAbsoluteValue. This norm computes the maximum of the absolute row sums.

The matrix p-norm is not available unless p element of StartSet 1 comma 2 comma normal infinity EndSet.

The following statements compute vector norms:

/* compute vector norms */
v = 1:5;
vn1 = norm(v, "L1");
vn2 = norm(v, "L2");
vnInf = norm(v, "LInf");
print vn1 vn2 vnInf;

Figure 281: Vector Norms

vn1vn2vnInf
157.41619855


You can also compute matrix norms, as follows:

x = {1 2, 3 4};
mn1 = norm(x, "L1");
mnF = norm(x, "Frobenius");
mnInf = norm(x, "LInf");
print mn1 mnF mnInf;

Figure 282: Matrix Norms

mn1mnFmnInf
65.47722567


The NORM function returns a missing value if any element of the argument contains a missing value.

Last updated: April 11, 2025