REPL UndefVarError: tr function

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!

Try searching the Julia documentation.

Try

julia> using LinearAlgebra

julia> x = randn(10,10)

julia> tr(x)

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

1 Like

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.

1 Like