Learn R Programming

LSAfun (version 0.8.1)

normalize: Normalize a vector

Description

Normalizes a character vector to a unit vector

Usage

normalize(x)

Value

The normalized vector as a numeric

Arguments

x

a numeric or integer vector

Author

Fritz Guenther

Details

The (euclidean) norm of a vector \(x\) is defined as

$$||x|| = \sqrt{\Sigma(x^2)}$$

To normalize a vector to a unit vector \(u\) with \(||u|| = 1\), the following equation is applied:

$$x' = x/ ||x||$$

Examples

Run this code
normalize(1:2)


## check vector norms:

x <- 1:2

sqrt(sum(x^2))              ## vector norm
sqrt(sum(normalize(x)^2))   ## norm = 1

Run the code above in your browser using DataLab