GramSchmidt | R Documentation |
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.
GramSchmidt(
X,
normalize = TRUE,
verbose = FALSE,
tol = sqrt(.Machine$double.eps),
omit_zero_columns = TRUE
)
X |
a matrix |
normalize |
logical; should the resulting columns be normalized to unit length? The default is |
verbose |
logical; if |
tol |
the tolerance for detecting linear dependencies in the columns of a. The default is |
omit_zero_columns |
if |
A matrix of the same size as X
, with orthogonal columns (but with 0 columns removed by default)
Phil Chalmers, John Fox
(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)
# A non-invertible matrix; hence, it is of deficient rank
(xx <- matrix(c( 1:3, 3:1, 1, 0, -1), 3, 3))
R(xx)
crossprod(xx)
# GramSchmidt finds an orthonormal basis
(zz <- GramSchmidt(xx))
zapsmall(crossprod(zz))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.