lu {fastmatrix} | R Documentation |
The LU factorization of a square matrix
Description
lu
computes the LU factorization of a matrix.
Usage
lu(x)
## Default S3 method:
lu(x)
## S3 method for class 'lu'
solve(a, b, ...)
is.lu(x)
Arguments
x |
a square numeric matrix whose LU factorization is to be computed. |
a |
an LU factorization of a square matrix. |
b |
a vector or matrix of right-hand sides of equations. |
... |
further arguments passed to or from other methods |
Details
The LU factorization plays an important role in many numerical procedures. In
particular it is the basic method to solve the equation \bold{Ax} = \bold{b}
for given matrix \bold{A}
, and vector \bold{b}
.
solve.lu
is the method for solve
for lu
objects.
is.lu
returns TRUE
if x
is a list
and inherits
from "lu"
.
Unsuccessful results from the underlying LAPACK code will result in an
error giving a positive error code: these can only be interpreted by
detailed study of the Fortran
code.
Value
The LU factorization of the matrix as computed by LAPACK. The components in
the returned value correspond directly to the values returned by DGETRF
.
lu |
a matrix with the same dimensions as |
pivot |
information on the pivoting strategy used during the factorization. |
Note
To compute the determinant of a matrix (do you really need it?),
the LU factorization is much more efficient than using eigenvalues
(eigen
). See det
.
LAPACK uses column pivoting and does not attempt to detect rank-deficient matrices.
References
Anderson. E., Bai, Z., Bischof, C., Blackford, S., Demmel, J., Dongarra, J., Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A. Sorensen, D. (1999). LAPACK Users' Guide, 3rd Edition. SIAM.
Golub, G.H., Van Loan, C.F. (1996). Matrix Computations, 3rd Edition. John Hopkins University Press.
See Also
extractL
, extractU
, constructX
for
reconstruction of the matrices,
lu2inv
Examples
a <- matrix(c(3,2,6,17,4,18,10,-2,-12), ncol = 3)
z <- lu(a)
z # information of LU factorization
# computing det(a)
prod(diag(z$lu)) # product of diagonal elements of U
# solve linear equations
b <- matrix(1:6, ncol = 2)
solve(z, b)