https://github.com/cran/pracma
Raw File
Tip revision: 392ae21a013fb3f518e8f9eb8efb458a55a2eca2 authored by HwB on 09 April 2011, 00:00:00 UTC
version 0.3-0
Tip revision: 392ae21
vnorm.R
##
##  v n o r m . R  Vector Norm
##


vnorm <- 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