R: Computes the p-norm of a vector

minkowski {fastmatrix} | R Documentation

## Computes the p-norm of a vector

### Description

Computes a p-norm of vector `x` using BLAS. The norm can be the one (`p = 1`) norm, Euclidean (`p = 2`) norm, the infinity (`p = Inf`) norm. For other values `p >= 1` the underlying `Fortran` code is based on ideas of BLAS Level 1.

### Usage

    minkowski(x, p = 2)

### Arguments

`x` | a numeric vector.
`p` | a number, specifying the type of norm desired. Possible values include real number greater or equal to 1, or Inf, Default value is `p = 2`.

### Details

Method of `minkowski` calls BLAS functions `dasum` (`p = 1`), `dnrm2` (`p = 2`), `idamax` (`p = Inf`). For other values, a `Fortran` subroutine using unrolled cycles is called.

### Value

The vector p-norm, a non-negative number.

### Examples

    # a tiny example
    x <- rnorm(1000)
    minkowski(x, p = 1)
    minkowski(x, p = 1.5)
    minkowski(x, p = 2)
    minkowski(x, p = Inf)

    x <- x / minkowski(x)
    minkowski(x, p = 2) # equal to 1

[Package fastmatrix version 0.2-3571 Index]