https://github.com/cran/pracma
Raw File
Tip revision: c79a04b5074656b36e591191eb8137b70a349932 authored by Hans W. Borchers on 30 June 2014, 00:00:00 UTC
version 1.7.0
Tip revision: c79a04b
norm.R
##
##  n o r m . R  Vector Norm
##


Norm <- function(x, p=2) {
    stopifnot(is.numeric(x) || is.complex(x),
              is.numeric(p), length(p) == 1)

    if (p > -Inf && p < Inf) sum(abs(x)^p)^(1/p)
    else if (p ==  Inf) max(abs(x))
    else if (p == -Inf) min(abs(x))
    else return(NULL)
}
back to top