|
Size: 3526
Comment:
|
← Revision 17 as of 2026-01-07 01:54:41 ⇥
Size: 3907
Comment: Details
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| = Elimination Matrices = | = LU Decomposition = |
| Line 3: | Line 3: |
| See [[LinearAlgebra/Elimination|Elimination]] for a walkthrough of '''elimination'''. This regards the computation of '''elimination matrices''', which are a method of computing elimination. | '''''LU'' decomposition''' is another approach to [[LinearAlgebra/Elimination|Gauss-Jordan elimination]]. It is generalized as '''''A''' = '''LU'''''. |
| Line 11: | Line 11: |
| == Introduction == | == Description == |
| Line 13: | Line 13: |
| Consider the below system of equations: | If a matrix '''''A''''' can be decomposed into [[LinearAlgebra/SpecialMatrices#Lower_Triangular_Matrices|lower]] and [[LinearAlgebra/SpecialMatrices#Upper_Triangular_Matrices|upper triangular matrices]] '''''L''''' and '''''U''''', the system can generally be solved by: 1. Let ''y = '''U'''x''. 2. Reformulate the original system as '''''L'''y = b''. This system's first equation simply states the value of ''y,,1,,''. The second equation gives ''y,,2,,'' in terms of ''y,,1,,'', which can be can be solved by substitution. And so on. 3. Solve for ''y''. 4. Reformulate the original problem as '''''U'''x = y''. As before, this system's last equation simply states the value of ''x,,n,,''. And so on. 5. Solve for ''x''. Furthermore, note that the [[LinearAlgebra/Invertibility|inverse]] matrix '''''A'''^-1^'' can be calculated as '''''U'''^-1^'''L'''^-1^''. |
| Line 16: | Line 23: |
| x + 2y + z = 2 3x + 8y + z = 12 4y + z = 2 |
julia> using LinearAlgebra julia> A = [1 2 1; 3 8 1; 0 4 1] 3×3 Matrix{Int64}: 1 2 1 3 8 1 0 4 1 julia> lu(A, NoPivot()) LU{Float64, Matrix{Float64}, Vector{Int64}} L factor: 3×3 Matrix{Float64}: 1.0 0.0 0.0 3.0 1.0 0.0 0.0 2.0 1.0 U factor: 3×3 Matrix{Float64}: 1.0 2.0 1.0 0.0 2.0 -2.0 0.0 0.0 5.0 |
| Line 20: | Line 44: |
Note that `NoPivot()` must be specified because [[Julia]] wants to do a more efficient factorization. ---- |
|
| Line 23: | Line 51: |
| == Formulation == | == Computation of Elimination Matrices == |
| Line 25: | Line 53: |
| The first step of elimination involves the elimination of the cell at row 2 column 1 ''(henceforward cell '''(2,1)''')''. | [[LinearAlgebra/Elimination|Gauss-Jordan elimination]] begins with identifying the pivot and transforming this: |
| Line 28: | Line 56: |
| [1] 2 1 [1] 2 1 3 8 1 -> 0 2 -2 0 4 1 0 4 1 |
┌ ┐ │ [1] 2 1│ │ 3 8 1│ │ 0 4 1│ └ ┘ |
| Line 33: | Line 63: |
| This can instead be formulated in matrices: | ...into this: {{{ ┌ ┐ │ [1] 2 1│ │ 0 2 -2│ │ 0 4 1│ └ ┘ }}} This transformation was ultimately a linear combination of rows: subtracting three of row 1 from row 2. This can be reformulated with matrices. |
| Line 55: | Line 95: |
| This elimination matrix is called E,,2 1,, because is eliminated cell (2,1). An elimination matrix is always the identity matrix with the negative of the multiplier in the elimination position. | This '''elimination matrix''' is called '''''E''',,2 1,,'' because it eliminated cell (2,1), the '''elimination cell'''. An elimination matrix is always the [[LinearAlgebra/SpecialMatrices#Identity_Matrix|identity matrix]] with the negated multiplier in the elimination cell. |
| Line 57: | Line 97: |
| Completing the elimination process: {{{ [1] 2 1 [1] 2 1 0 [2] -2 -> 0 [2] -2 0 4 1 0 0 5 }}} This can be formulated as E,,3 2,, (E,,2 1,, A) = U. Note that this is equivalent to (E,,3 2,, E,,2 1,,) A = U. |
The Gauss-Jordan approach continues with subtracting two of row 2 from row 3. Formulated as matrices instead: |
| Line 85: | Line 117: |
| == Factorization == | == Decomposition as LU == |
| Line 87: | Line 119: |
| It is preferable to refactor (E,,3 2,, E,,2 1,,) A = U into A = L U. L can be trivially solved to be E,,2 1,,^-1^ E,,3 2,,^-1^. Furthermore, because elimination matrices are modifications of the inverse matrix, their inverses are also trivial to solve. Note that these are simply the identity matrix with the (normal, non-negative) multiplier in the elimination position | In this specific example, elimination can be written out as ''('''E''',,3 2,,'''E''',,2 1,,)'''A''' = '''U'''''. A preferable form is '''''A''' = '''LU''''', where '''''L''''' takes on the role of all elimination matrices. '''''L''''' may be a [[LinearAlgebra/SpecialMatrices#Lower_Triangular_Matrices|lower triangular matrix]]. In this specific example, '''''L''' = '''E''',,2 1,,^-1^'''E''',,3 2,,^-1^''. See below how '''''E''',,3 2,,'''E''',,2 1,,'' is messier than '''''E''',,2 1,,^-1^'''E''',,3 2,,^-1^'' despite needing to compute [[LinearAlgebra/Invertibility|inverses]]: |
| Line 90: | Line 126: |
| ┌ ┐ -1 │ 1 0 0│ E E = │ 0 1 0│ 2,3 2,3 │ 0 0 1│ └ ┘ ┌ ┐ ┌ ┐ │ 1 0 0│ -1 │ 1 0 0│ │ -3 1 0│ E = │ 0 1 0│ │ 0 0 1│ 2,3 │ 0 0 1│ └ ┘ └ ┘ ┌ ┐ -1 │ 1 0 0│ E = │ 3 1 0│ 2,3 │ 0 0 1│ └ ┘ |
julia> E3_2 * E2_1 3×3 Matrix{Int64}: 1 0 0 -3 1 0 6 -2 1 julia> convert(Matrix{Int64}, inv(E2_1) * inv(E3_2)) 3×3 Matrix{Int64}: 1 0 0 3 1 0 0 2 1 |
| Line 107: | Line 139: |
| The fundamental reason for factorization is that the singular product of E,,3 2,, E,,2 1,, is messier than that of E,,2 1,,^-1^ E,,3 2,,^-1^ {{{ E E = ? 3,2 2,1 ┌ ┐┌ ┐ ┌ ┐ │ 1 0 0││ 1 0 0│ │ 1 0 0│ │ 0 1 0││ -3 1 0│ = │ -3 1 0│ │ 0 -2 1││ 0 0 1│ │ 6 -2 1│ └ ┘└ ┘ └ ┘ -1 -1 E E = L 2,1 3,2 ┌ ┐┌ ┐ ┌ ┐ │ 1 0 0││ 1 0 0│ │ 1 0 0│ │ 3 1 0││ 0 1 0│ = │ 3 1 0│ │ 0 0 1││ 0 2 1│ │ 0 2 1│ └ ┘└ ┘ └ ┘ }}} In particular, cell (3,1) is a 0 in L but is 6 in E,,3 2,, E,,2 1,,. ---- == Permutation == If a zero pivot is reached, rows must be exchanged. This can be expressed with matrices as P A = L U. See [[LinearAlgebra/PermutationMatrices|Permutation Matrices]] for more information on these matrices and their properties. |
Furthermore, in this expression, elimination matrices are iteratively appended instead of prepended. |
LU Decomposition
LU decomposition is another approach to Gauss-Jordan elimination. It is generalized as A = LU.
Description
If a matrix A can be decomposed into lower and upper triangular matrices L and U, the system can generally be solved by:
Let y = Ux.
Reformulate the original system as Ly = b. This system's first equation simply states the value of y1. The second equation gives y2 in terms of y1, which can be can be solved by substitution. And so on.
Solve for y.
Reformulate the original problem as Ux = y. As before, this system's last equation simply states the value of xn. And so on.
Solve for x.
Furthermore, note that the inverse matrix A-1 can be calculated as U-1L-1.
julia> using LinearAlgebra
julia> A = [1 2 1; 3 8 1; 0 4 1]
3×3 Matrix{Int64}:
1 2 1
3 8 1
0 4 1
julia> lu(A, NoPivot())
LU{Float64, Matrix{Float64}, Vector{Int64}}
L factor:
3×3 Matrix{Float64}:
1.0 0.0 0.0
3.0 1.0 0.0
0.0 2.0 1.0
U factor:
3×3 Matrix{Float64}:
1.0 2.0 1.0
0.0 2.0 -2.0
0.0 0.0 5.0Note that NoPivot() must be specified because Julia wants to do a more efficient factorization.
Computation of Elimination Matrices
Gauss-Jordan elimination begins with identifying the pivot and transforming this:
┌ ┐ │ [1] 2 1│ │ 3 8 1│ │ 0 4 1│ └ ┘
...into this:
┌ ┐ │ [1] 2 1│ │ 0 2 -2│ │ 0 4 1│ └ ┘
This transformation was ultimately a linear combination of rows: subtracting three of row 1 from row 2. This can be reformulated with matrices.
julia> A = [1 2 1; 3 8 1; 0 4 1]
3×3 Matrix{Int64}:
1 2 1
3 8 1
0 4 1
julia> E2_1 = [1 0 0; -3 1 0; 0 0 1]
3×3 Matrix{Int64}:
1 0 0
-3 1 0
0 0 1
julia> E2_1 * A
3×3 Matrix{Int64}:
1 2 1
0 2 -2
0 4 1This elimination matrix is called E2 1 because it eliminated cell (2,1), the elimination cell. An elimination matrix is always the identity matrix with the negated multiplier in the elimination cell.
The Gauss-Jordan approach continues with subtracting two of row 2 from row 3. Formulated as matrices instead:
julia> E3_2 = [1 0 0; 0 1 0; 0 -2 1]
3×3 Matrix{Int64}:
1 0 0
0 1 0
0 -2 1
julia> E3_2 * E2_1 * A
3×3 Matrix{Int64}:
1 2 1
0 2 -2
0 0 5
Decomposition as LU
In this specific example, elimination can be written out as (E3 2E2 1)A = U.
A preferable form is A = LU, where L takes on the role of all elimination matrices. L may be a lower triangular matrix. In this specific example, L = E2 1-1E3 2-1.
See below how E3 2E2 1 is messier than E2 1-1E3 2-1 despite needing to compute inverses:
julia> E3_2 * E2_1
3×3 Matrix{Int64}:
1 0 0
-3 1 0
6 -2 1
julia> convert(Matrix{Int64}, inv(E2_1) * inv(E3_2))
3×3 Matrix{Int64}:
1 0 0
3 1 0
0 2 1Furthermore, in this expression, elimination matrices are iteratively appended instead of prepended.
