在julia中矩阵的迹怎么计算

使用trace这个函数报错,求解
image

julia> using LinearAlgebra
help?> tr
search: tr try triu tril trunc trues triu! tril! trylock tryparse truncate transcode transpose transpose! Transpose Tridiagonal trailing_ones trailing_zeros Ptr strip struct String string stride strides atreplinit

  tr(M)

  Matrix trace. Sums the diagonal elements of M.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> A = [1 2; 3 4]
  2×2 Array{Int64,2}:
   1  2
   3  4
  
  julia> tr(A)
  5

1赞

超级感谢,解决了我的问题!!!

京ICP备17009874号-2