LU | R Documentation |
LU
computes the LU decomposition of a matrix, A
, such that P A = L U
,
where L
is a lower triangle matrix, U
is an upper triangle, and P
is a
permutation matrix.
LU(A, b, tol = sqrt(.Machine$double.eps), verbose = FALSE, ...)
A |
coefficient matrix |
b |
right-hand side vector. When supplied the returned object will also contain the solved
|
tol |
tolerance for checking for 0 pivot |
verbose |
logical; if |
... |
additional arguments passed to |
The LU decomposition is used to solve the equation A x = b
by calculating
L(Ux - d) = 0
, where Ld = b
. If row exchanges are necessary for
A
then the permutation matrix P
will be required to exchange the rows in A
;
otherwise, P
will be an identity matrix and the LU equation will be simplified to
A = L U
.
A list of matrix components of the solution, P
, L
and U
. If b
is supplied, the vectors d
and x
are also returned.
Phil Chalmers
A <- matrix(c(2, 1, -1,
-3, -1, 2,
-2, 1, 2), 3, 3, byrow=TRUE)
b <- c(8, -11, -3)
(ret <- LU(A)) # P is an identity; no row swapping
with(ret, L %*% U) # check that A = L * U
LU(A, b)
LU(A, b, verbose=TRUE)
LU(A, b, verbose=TRUE, fractions=TRUE)
# permutations required in this example
A <- matrix(c(1, 1, -1,
2, 2, 4,
1, -1, 1), 3, 3, byrow=TRUE)
b <- c(1, 2, 9)
(ret <- LU(A, b))
with(ret, P %*% A)
with(ret, L %*% U)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.