| norm {base} | R Documentation |
Compute the Norm of a Matrix
Description
Computes a matrix norm of x using LAPACK. The norm can be
the one ("O") norm, the infinity ("I") norm, the
Frobenius ("F") norm, the maximum modulus ("M") among
elements of a matrix, or the “spectral” or "2"-norm, as
determined by the value of type.
Usage
norm(x, type = c("O", "I", "F", "M", "2"))
Arguments
x |
numeric matrix; note that packages such as Matrix
define more |
type |
character string, specifying the type of matrix norm to be computed. A character indicating the type of norm desired.
The default is |
Details
The base method of norm() calls the LAPACK function
dlange.
Note that the 1-, Inf- and "M" norm is faster to calculate than
the Frobenius one.
Unsuccessful results from the underlying LAPACK code will result in an error giving a positive error code: these can only be interpreted by detailed study of the FORTRAN code.
Value
The matrix norm, a non-negative number. Zero for a 0-extent (empty) matrix.
Source
Except for norm = "2", the LAPACK routine DLANGE.
LAPACK is from https://netlib.org/lapack/.
References
Anderson E., Bai Z., Bischof C., Blackford S., Demmel J., Dongarra J. J., Du Croz J., Greenbaum A., Hammerling S., McKenney A., Sorensen D. C. (1999). LAPACK Users' Guide, series Software, Environments, and Tools, Third edition. Society for Industrial and Applied Mathematics, Philadelphia, PA. ISBN 9780898714470. doi:10.1137/1.9780898719604. https://netlib.org/lapack/lug/lapack_lug.html.
See Also
rcond for the (reciprocal) condition number.
Examples
(x1 <- cbind(1, 1:10))
norm(x1)
norm(x1, "I")
norm(x1, "M")
stopifnot(all.equal(norm(x1, "F"),
sqrt(sum(x1^2))))
hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, `+`) }
h9 <- hilbert(9)
## all 5 (4 different) types of norm:
(nTyp <- eval(formals(base::norm)$type))
sapply(nTyp, norm, x = h9)
stopifnot(exprs = { # 0-extent matrices:
sapply(nTyp, norm, x = matrix(, 1,0)) == 0
sapply(nTyp, norm, x = matrix(, 0,0)) == 0
})