I assume that you want to do LU factorization of matrix A
:
julia> A = [1 3 3 2;2 6 9 7; -1 -1 3 4]
3×4 Array{Int64,2}:
1 3 3 2
2 6 9 7
-1 -1 3 4
julia> using LinearAlgebra
julia> L,U,p = lu(A)
LU{Float64,Array{Float64,2}}
L factor:
3×3 Array{Float64,2}:
1.0 0.0 0.0
-0.5 1.0 0.0
0.5 0.0 1.0
U factor:
3×4 Array{Float64,2}:
2.0 6.0 9.0 7.0
0.0 2.0 7.5 7.5
0.0 0.0 -1.5 -1.5
Here, p
is the row permutation of A
such that L*U = A[p,:]
:
julia> L*U
3×4 Array{Float64,2}:
2.0 6.0 9.0 7.0
-1.0 -1.0 3.0 4.0
1.0 3.0 3.0 2.0
julia> A[p,:]
3×4 Array{Int64,2}:
2 6 9 7
-1 -1 3 4
1 3 3 2
In other words: if you seek to solve A*x = b
, it follows that L*U*x = b[p]
, or U*x = L\b[p]
.
Example: b = [1,2,3]
:
julia> b = [1,2,3]
3-element Array{Int64,1}:
1
2
3
julia> A\b
4-element Array{Float64,1}:
-3.3333333333333526
2.0000000000000067
-1.666666666666658
1.6666666666666567
Alternatively:
julia> U\(L\b[p])
4-element Array{Float64,1}:
-3.333333333333332
1.9999999999999987
-1.6666666666666656
1.6666666666666674