Learn R Programming

splus2R (version 1.0-1)

vecnorm: p-norm of a vector

Description

Computes the p-norm of a vector

Usage

vecnorm(x, p=2)

Arguments

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, Inf, or character strings "euclidean" or "maximum". Default: 2.

Value

  • requested p-norm of input vector.

concept

splus

See Also

anyMissing, as.rectangular, colIds, colMaxs, colMedians, colMins, colRanges, colStdevs, colVars, deparseText, ifelse1, is.numeric.atomic.vector, is.rectangular, is.missing, is.zero, lowerCase, oldUnclass, numCols, numRows, peaks, positions, rowIds, rowMaxs, rmvnorm, stdev, subscript2d, upperCase, which.na.

Examples

Run this code
## 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)

Run the code above in your browser using DataLab