Aliases: norm norm,ANY,missing-method norm,denseMatrix,character-method norm,dgeMatrix,character-method norm,diagonalMatrix,character-method norm,dspMatrix,character-method norm,dsyMatrix,character-method norm,dtpMatrix,character-method norm,dtrMatrix,character-method norm,sparseMatrix,character-method
Keywords: algebra
### ** Examples x <- Hilbert(9) norm(x)# = "O" = "1"
[1] 2.828968
stopifnot(identical(norm(x), norm(x, "1"))) norm(x, "I")# the same, because 'x' is symmetric
[1] 2.828968
allnorms <- function(d) vapply(c("1","I","F","M","2"), norm, x = d, double(1)) allnorms(x)
1 I F M 2 2.828968 2.828968 1.755872 1.000000 1.725883
allnorms(Hilbert(10))
1 I F M 2 2.928968 2.928968 1.785527 1.000000 1.751920
i <- c(1,3:8); j <- c(2,9,6:10); x <- 7 * (1:7) A <- sparseMatrix(i, j, x = x) ## 8 x 10 "dgCMatrix" (sA <- sparseMatrix(i, j, x = x, symmetric = TRUE)) ## 10 x 10 "dsCMatrix"
10 x 10 sparse Matrix of class "dsCMatrix" [1,] . 7 . . . . . . . . [2,] 7 . . . . . . . . . [3,] . . . . . . . . 14 . [4,] . . . . . 21 . . . . [5,] . . . . . . 28 . . . [6,] . . . 21 . . . 35 . . [7,] . . . . 28 . . . 42 . [8,] . . . . . 35 . . . 49 [9,] . . 14 . . . 42 . . . [10,] . . . . . . . 49 . .
(tA <- sparseMatrix(i, j, x = x, triangular= TRUE)) ## 10 x 10 "dtCMatrix"
10 x 10 sparse Matrix of class "dtCMatrix" [1,] . 7 . . . . . . . . [2,] . . . . . . . . . . [3,] . . . . . . . . 14 . [4,] . . . . . 21 . . . . [5,] . . . . . . 28 . . . [6,] . . . . . . . 35 . . [7,] . . . . . . . . 42 . [8,] . . . . . . . . . 49 [9,] . . . . . . . . . . [10,] . . . . . . . . . .
(allnorms(A) -> nA)
1 I F M 2 56.00000 49.00000 82.82512 49.00000 49.00000
allnorms(sA)
1 I F M 2 84.00000 84.00000 117.13240 49.00000 61.54212
allnorms(tA)
1 I F M 2 56.00000 49.00000 82.82512 49.00000 49.00000
stopifnot(all.equal(nA, allnorms(as(A, "matrix"))), all.equal(nA, allnorms(tA))) # because tA == rbind(A, 0, 0) A. <- A; A.[1,3] <- NA stopifnot(is.na(allnorms(A.))) # gave error