rand_ortho_vector {clugenr}R Documentation

Get a random unit vector orthogonal to u.

Description

Get a random unit vector orthogonal to u.

Usage

rand_ortho_vector(u)

Arguments

u

A unit vector.

Value

A random unit vector orthogonal to u.

Note

This function is stochastic. For reproducibility set a PRNG seed with set.seed.

Examples

r <- stats::runif(3)      # Get a random 3D vector
r <- r / norm(r, "2")     # Normalize it
o <- rand_ortho_vector(r) # Get a random unit vector orthogonal to r
r %*% o            # Check that r and o are orthogonal (result should be ~0)

[Package clugenr version 1.0.3 Index]