Learn R Programming

pracma (version 0.4-0)

vectornorm: Vector Norm

Description

The vectornorm function calculates several different types of vector norms for x, depending on the argument p.

Usage

vectornorm(x, p = 2)

Arguments

x
Numeric vector; matrices not allowed.
p
Numeric scalar or Inf, -Inf; default is 2

Value

  • Numeric scalar (or Inf), or NA if an element of x is NA.

Details

vectornorm returns a scalar that gives some measure of the magnitude of the elements of x. It is called the $p$-norm for values $-Inf \le p \le Inf$, defining Hilbert spaces on $R^n$.

vectornorm(x) is the Euclidean length of a vecor x; same as vectornorm(x, 2). vectornorm(x, p) for finite p is defined as sum(abs(A)^p)^(1/p). vectornorm(x, Inf) returns max(abs(x)), while vectornorm(x, -Inf) returns min(abs(x)).

See Also

norm of a matrix

Examples

Run this code
vectornorm(c(3, 4))          #=> 5  Pythagoras triple
vectornorm(c(1, 1, 1), p=2)  #   sqrt(3)
vectornorm(1:10, p = 1)      #   sum(1:10)
vectornorm(1:10, p = 0)      #   Inf
vectornorm(1:10, p = Inf)    #   max(1:10)
vectornorm(1:10, p = -Inf)   #   min(1:10)

Run the code above in your browser using DataLab