Description Usage Arguments Value See Also Examples
Computes the p-norm of a vector
1 | vecnorm(x, p=2)
|
x |
the vector whose norm is sought (either numeric or complex). |
p |
a number or character string indicating the type of norm desired. Possible values include real number greater or
equal to 1, |
requested p-norm of input vector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## compare 2-norm calculations
x <- rnorm(100)
sqrt(sum(x*x))
vecnorm(x)
## 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))
vecnorm(x)
## 1-norm comparison
sum(abs(x))
vecnorm(x, p=1)
## L-infinity norm comparison
max(abs(x))
vecnorm(x, p=Inf)
|
[1] 11.26178
[1] 11.26178
[1] Inf
[1] 2.681562e+154
[1] 5.363123e+154
[1] 5.363123e+154
[1] 1.340781e+154
[1] 1.340781e+154
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.