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:
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:
. An equivalent alias is "CityBlock" or "Manhattan".
- "L2"
specifies that the function compute the Euclidean 2-norm:
. This is the default value. An equivalent alias is "Euclidean" or "Frobenius".
- "LInf"
-
specifies that the function compute the
-norm:
.
An equivalent alias is "Chebyshev".
- p
Methods for Matrix Norms
For an matrix A such that
and
, the method argument has the following valid values:
- "Frobenius"
- "L1"
specifies the matrix 1-norm:
. 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
matrix. This quantity can be expensive to compute because the function internally computes eigenvalues.
- "LInf"
specifies the
-norm:
. This norm computes the maximum of the absolute row sums.
The matrix p-norm is not available unless .
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
| vn1 | vn2 | vnInf |
|---|---|---|
| 15 | 7.4161985 | 5 |
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
| mn1 | mnF | mnInf |
|---|---|---|
| 6 | 5.4772256 | 7 |
The NORM function returns a missing value if any element of the argument contains a missing value.