# LU Factorization

I am just confused about one thing related to LU factorization. It is known that the solution of `A.x=b` is x = U\L\P*b. Why when I apply it in the below it gives another solution comparing with `A\b`, while `LU\b` gives the same result?

``````A = [1 3 3; 6 9 7;-3 3 4]; b = [1,2,3];

julia> A\b
3-element Vector{Float64}:
-0.6000000000000001
0.9333333333333331
-0.39999999999999974

LU = lu(A);

julia> LU.U\LU.L\(LU.P)*b
3-element Vector{Float64}:
46.00000000000013
53.0000000000001
-17.933333333333373

julia> LU\b
3-element Vector{Float64}:
-0.6000000000000001
0.9333333333333331
-0.39999999999999974

``````

Just need to add more parentheses:

``````julia> LU.U\(LU.L\(LU.P)*b)
3-element Vector{Float64}:
-0.6
0.9333333333333333
-0.4000000000000001
``````
2 Likes

`\` is left-associative in Julia, so this is parsed as

``````(LU.U\LU.L)\(LU.P*b)
``````

whereas you want:

``````LU.U\(LU.L\(LU.P*b))
``````

or equivalently `LU.U\(LU.L\b[LU.p])`, which gives the same answer as `A \ b`.

2 Likes

Thank you very much! I got it