lp_norm | R Documentation |
Computes the \ell^p
norm of an n-dimensional (real/complex)
vector \mathbf{x} \in \mathbf{C}^n
\left|\left| \mathbf{x} \right|\right|_p = \left( \sum_{i=1}^n
\left| x_i \right|^p \right)^{1/p}, p \in [0, \infty],
where \left| x_i \right|
is the absolute value of x_i
. For
p=2
this is Euclidean norm; for p=1
it is Manhattan norm. For
p=0
it is defined as the number of non-zero elements in
\mathbf{x}
; for p = \infty
it is the maximum of the absolute
values of \mathbf{x}
.
The norm of \mathbf{x}
equals 0
if and only if \mathbf{x} =
\mathbf{0}
.
lp_norm(x, p = 2)
x |
n-dimensional vector (possibly complex values) |
p |
which norm? Allowed values |
Non-negative float, the norm of \mathbf{x}
.
kRealVec <- c(3, 4)
# Pythagoras
lp_norm(kRealVec)
# did not know Manhattan,
lp_norm(kRealVec, p = 1)
# so he just imagined running in circles.
kComplexVec <- exp(1i * runif(20, -pi, pi))
plot(kComplexVec)
sapply(kComplexVec, lp_norm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.