Search⌘ K
AI Features

LU Matrix Factorization

Explore how to implement LU matrix factorization using R and C++ libraries RcppArmadillo and RcppEigen. Understand the decomposition into lower and upper triangular matrices, validate results by reconstructing original matrices, and gain practical skills to solve linear systems efficiently.

What is LU factorization?

An LU factorization refers to the factorization of a square matrix 𝐴𝐴, with proper row and/or column orderings or permutations, into two factors:

  • A lower triangular matrix 𝐿𝐿
  • An upper triangular matrix π‘ˆπ‘ˆ

𝐴=πΏπ‘ˆπ΄ = πΏπ‘ˆ

R
A <- matrix(c(1, -1, 2, 2),
nrow = 2,
byrow = TRUE)
fA <- LU(A = A) # compute the LU factorization of A
A_ <- fA$P%*%fA$L%*%fA$U # retrieve the original matrix A by multiplying all factors
fA
A_

Explanation

The resulting LU factors are:

fA <- LU(A = A)

P, L, U factors

P=[1001]    L=[1021]    U=[1βˆ’104] P= \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \space\space\space\space L= \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix} \space\space\space\space U= \begin{bmatrix} 1 & -1 \\ 0 & 4 \end{bmatrix} ...