Failure of plain LU factorization¶
Here is the previously solved system.
using FundamentalsNumericalComputation
A = [2 0 4 3 ; -4 5 -7 -10 ; 1 15 2 -4.5 ; -2 0 2 -13];
b = [ 4, 9, 29, 40 ];
It has a perfectly good solution, obtainable through LU factorization.
L,U = FNC.lufact(A)
x = FNC.backsub( U, FNC.forwardsub(L,b) )
4-element Array{Float64,1}:
-3.0
1.0
4.0
-2.0
If we swap the second and fourth equations, nothing essential is changed, and Julia still finds the solution.
A[[2,4],:] = A[[4,2],:]
b[[2,4]] = b[[4,2]]
x = A\b
4-element Array{Float64,1}:
-3.0000000000000138
1.000000000000001
4.000000000000004
-1.9999999999999973
However, LU factorization fails.
L,U = FNC.lufact(A)
L
4×4 Array{Float64,2}:
1.0 0.0 0.0 0.0
-1.0 1.0 0.0 0.0
0.5 Inf 1.0 0.0
-2.0 Inf NaN 1.0