hypersphere.sample {hitandrun}R Documentation

Sample uniformly from an n-hypersphere

Description

Generates uniform random variates over an n-hypersphere

Usage

hypersphere.sample(n, N)

Arguments

n

Dimension of the hypersphere

N

Number of samples

Value

A single n-dimensional sample from the hypersphere.

Author(s)

Tommi Tervonen <tommi@smaa.fi>

Examples

n <- 3 # Dimension
N <- 5 # Nr samples

sample <- hypersphere.sample(n, N)

# Check summing to unity
vec.norm <- function(x) { sum(x^2) }
stopifnot(all.equal(apply(sample, 1, vec.norm), rep(1, N)))

[Package hitandrun version 0.5-6 Index]