# REPL UndefVarError: tr function

**URL:** <https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896>\
**Category:** New to Julia\
**Tags:** linearalgebra, matrices\
**Created:** [June 27, 2023, 2:55pm UTC](https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896 "2023-06-27T14:55:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dharmik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dharmik/32/51086_2.png) [@dharmik](https://discourse.julialang.org/u/dharmik)\
**Post date:** [June 27, 2023, 2:55pm UTC](https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896/1 "2023-06-27T14:55:31Z")

</div>

Hi! I’m trying to find the trace of a matrix: `A = reshape(1:m*n,m,n)` with `m=1000` and `n=500`, by writing `tr(A)` which is what the documentation instructs. However, I get the following error:

**ERROR:** UndefVarError: `tr` not defined  
Stacktrace:  
[1] top-level scope

I have no idea how to resolve this, as I thought the `tr` function was basic to the language and I didn’t need to do anything beforehand to use it. Perhaps that’s where I am going wrong here.

I’d appreciate any help. Thank you!

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [June 27, 2023, 3:02pm UTC](https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896/2 "2023-06-27T15:02:31Z")

</div>

Try searching the [Julia documentation](https://docs.julialang.org/en/v1/).

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [June 27, 2023, 3:04pm UTC](https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896/3 "2023-06-27T15:04:23Z")

</div>

Try

```julia
julia> using LinearAlgebra

julia> x = randn(10,10)

julia> tr(x)

```

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [June 27, 2023, 3:04pm UTC](https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896/4 "2023-06-27T15:04:47Z")

</div>

You need to first issue `using LinearAlgebra` (which is its own module).

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [June 27, 2023, 3:08pm UTC](https://discourse.julialang.org/t/repl-undefvarerror-tr-function/100896/5 "2023-06-27T15:08:07Z")

</div>

Welcome to the discussion!

Sometimes, if you are just skimming the documentation online - you might notice at the top of the page it will say something like “Standard Library / Linear Algebra.” The folks writing the examples in the page often don’t issue `using LinearAlgebra`, since they assume you have arrived at the page looking for the documentation for the package.
