GramSchmidt

0th

Percentile

Gram-Schmidt Orthogonalization of a Matrix

Carries out simple Gram-Schmidt orthogonalization of a matrix. Treating the columns of the matrix X in the given order, each successive column after the first is made orthogonal to all previous columns by subtracting their projections on the current column.

Usage
GramSchmidt(X, normalize = TRUE, verbose = FALSE,
  tol = sqrt(.Machine$double.eps))
Arguments
X

a matrix

normalize

logical; should the resulting columns be normalized to unit length?

verbose

logical; if TRUE, print intermediate steps

tol

the tolerance for detecting linear dependencies in the columns of a. The default is .Machine$double.eps

Value

A matrix of the same size as X, with orthogonal columns

Aliases
  • GramSchmidt
Examples
# NOT RUN {
(xx <- matrix(c( 1:3, 3:1, 1, 0, -2), 3, 3))
crossprod(xx)
(zz <- GramSchmidt(xx, normalize=FALSE))
zapsmall(crossprod(zz))

# normalized
(zz <- GramSchmidt(xx))
zapsmall(crossprod(zz))

# print steps
GramSchmidt(xx, verbose=TRUE)

# non-invertible matrix; hence, its basis is not orthonormal
(xx <- matrix(c( 1:3, 3:1, 1, 0, -1), 3, 3))
crossprod(xx)
(zz <- GramSchmidt(xx))
zapsmall(crossprod(zz))

# }
Documentation reproduced from package matlib, version 0.9.2, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.