vecnorm.RdComputes the p-norm of a vector
vecnorm(x, p=2)requested p-norm of input vector.
## compare 2-norm calculations
x <- rnorm(100)
sqrt(sum(x*x))
#> [1] 10.59982
vecnorm(x)
#> [1] 10.59982
## compare 2-norm of series which sums to Inf. The
## vecnorm returns a finite value in this case.
x <- rep(sqrt(.Machine$double.xmax), 4)
sqrt(sum(x*x))
#> [1] Inf
vecnorm(x)
#> [1] 2.681562e+154
## 1-norm comparison
sum(abs(x))
#> [1] 5.363123e+154
vecnorm(x, p=1)
#> [1] 5.363123e+154
## L-infinity norm comparison
max(abs(x))
#> [1] 1.340781e+154
vecnorm(x, p=Inf)
#> [1] 1.340781e+154