# Storing the LU decomposition of a matrix

**URL:** <https://discourse.julialang.org/t/storing-the-lu-decomposition-of-a-matrix/122138>\
**Category:** Numerics\
**Tags:** question\
**Created:** [November 1, 2024, 2:42pm UTC](https://discourse.julialang.org/t/storing-the-lu-decomposition-of-a-matrix/122138 "2024-11-01T14:42:53Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [November 1, 2024, 4:11pm UTC](https://discourse.julialang.org/t/storing-the-lu-decomposition-of-a-matrix/122138/4 "2024-11-01T16:11:59Z")

</div>

This section of the manual might help clear things up: [Scope of Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#scope-of-variables)

Inside your `logpdf!` function, `Y = lu(x)` rebinds `Y` to a new value `lu(X)`, but only within the function’s local scope. This doesn’t affect the global `Y` because it’s a different `Y` that only exists inside your function. Your local `Y` [shadows](https://en.wikipedia.org/wiki/Variable_shadowing) the `Y` passed as the argument.

And if you find all this a bit confusing, you’re not alone:

> [@The manual's section on variable scope sucks](https://discourse.julialang.org/t/the-manuals-section-on-variable-scope-sucks/119522):
>
> I know it’s not for the lack of trying, but the manual’s section on scope is unclear if not outright wrong. Issue 1 The manual says: If you assign to an existing local, it always [emphasis not mine] updates that existing local: you can only shadow a local by explicitly declaring a new local in a nested scope with the local keyword. a few lines below, it says: When x = occurs in a local scope, Julia applies the following rules to decide what the expression means based on where the assign…

---

_[View the full topic](https://discourse.julialang.org/t/storing-the-lu-decomposition-of-a-matrix/122138)._
