# LU Factorization

**URL:** <https://discourse.julialang.org/t/lu-factorization/87841>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 26, 2022, 9:01pm UTC](https://discourse.julialang.org/t/lu-factorization/87841 "2022-09-26T21:01:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [September 26, 2022, 9:01pm UTC](https://discourse.julialang.org/t/lu-factorization/87841/1 "2022-09-26T21:01:40Z")

</div>

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?

```julia
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

```

---

<div class="post-metadata">

**Author:** ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Post date:** [September 26, 2022, 9:09pm UTC](https://discourse.julialang.org/t/lu-factorization/87841/2 "2022-09-26T21:09:38Z")

</div>

Just need to add more parentheses:

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

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 26, 2022, 9:11pm UTC](https://discourse.julialang.org/t/lu-factorization/87841/3 "2022-09-26T21:11:02Z")

</div>

> [@Amro](#):
>
> `LU.U\LU.L\(LU.P)*b`

`\` is [left-associative in Julia](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity), so this is parsed as

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

```

whereas you want:

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

```

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

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [September 26, 2022, 9:13pm UTC](https://discourse.julialang.org/t/lu-factorization/87841/4 "2022-09-26T21:13:11Z")

</div>

Thank you very much! I got it
