LU {matlib}R Documentation

LU Decomposition

Description

LU computes the LU decomposition of a matrix, AA, such that PA=LUP A = L U, where LL is a lower triangle matrix, UU is an upper triangle, and PP is a permutation matrix.

Usage

LU(A, b, tol = sqrt(.Machine$double.eps), verbose = FALSE, ...)

Arguments

A

coefficient matrix

b

right-hand side vector. When supplied the returned object will also contain the solved dd and x elements

tol

tolerance for checking for 0 pivot

verbose

logical; if TRUE, print intermediate steps

...

additional arguments passed to showEqn

Details

The LU decomposition is used to solve the equation Ax=bA x = b by calculating L(Uxd)=0L(Ux - d) = 0, where Ld=bLd = b. If row exchanges are necessary for AA then the permutation matrix PP will be required to exchange the rows in AA; otherwise, PP will be an identity matrix and the LU equation will be simplified to A=LUA = L U.

Value

A list of matrix components of the solution, P, L and U. If b is supplied, the vectors dd and x are also returned.

Author(s)

Phil Chalmers

Examples


  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)


[Package matlib version 0.9.8 Index]