p-norm of a Vector

DESCRIPTION:

Computes the p-norm of a vector.

USAGE:

vecnorm(x, p = 2) 

REQUIRED ARGUMENTS:

x
the vector whose norm is sought (either numeric or complex).

OPTIONAL ARGUMENTS:

p
a number or character string indicating the type of norm desired. Possible values include real number greater or equal to 1, Inf, or character strings "euclidean" or "maximum".

VALUE:

the p-norm of x. This is defined as:

[(x1)**p + (x2)**p + ....+(xn)**p]***(1/p) for p greater than or equal to 1.

METHOD:

Computation of the 2 norm is based on the function dnrm2 Linpack BLAS (Dongarra et al. 1979). For 1 < p < Inf, p-norms are computed so as to avoid overflow and underflow. The numerical value of a norm may differ for vectors which have the same elements appearing in a different order. Sorting a vector so that the elements of smallest modulus appear first may help reduce this roundoff error.

REFERENCES:

Dongarra, J. J., Bunch, J. R., Moler, C. B., and Stewart, G. W. (1979). Linpack User's Guide. SIAM, Philadelphia.

SEE ALSO:

, , , , , .

EXAMPLES:

x <-  rnorm(100) 
sqrt(sum(x*x)) 
vecnorm(x) 
x <- rep(sqrt(.Machine$double.xmax), 4) 
sqrt(sum(x*x)) 
vecnorm(x)  
sum(abs(x)) 
vecnorm(x, p = 1) 
max(abs(x)) 
vecnorm(x, p = Inf)