lq: LQ decomposition.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/basic_tensor.R

Description

Computes the LQ decomposition of a matrix.

Usage

1
lq(X)

Arguments

X

A n by p matrix of rank n.

Details

If X is an n by p matrix with n ≤ p, then lq computes the LQ decomposition of X. That is, X = LQ' where Q is p by n with orthonormal columns and L is n by n lower triangular with positive diaognal entries.

Value

L An n by n lower triangular matrix with positive diagonal entries.

Q An n by p matrix with orthonormal columns.

The returned values satisfy X = L %*% t(Q), up to numerical precision.

Author(s)

David Gerard.

See Also

qr2 for the related QR decomposition.

Examples

1
2
3
4
5
6
7
8
X <- matrix(stats::rnorm(12), nrow = 3)
lq_X <- lq(X)
L <- lq_X$L
Q <- lq_X$Q
L
Q
trim(t(Q) %*% Q)
trim(X - L%*%t(Q))

Example output

           [,1]      [,2]      [,3]
[1,]  1.7013508 0.0000000 0.0000000
[2,] -0.9916113 2.1371754 0.0000000
[3,] -0.1397849 0.5026932 0.8693234
           [,1]      [,2]        [,3]
[1,] -0.1505313 0.8094839 -0.07419913
[2,]  0.1372855 0.1322648  0.98136427
[3,]  0.9628331 0.2059868 -0.16394063
[4,] -0.1773286 0.5336772 -0.06739535
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1
     [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0

tensr documentation built on May 29, 2017, 9:44 a.m.