Syntax: @trace(m)
m: matrix, sym
Return: scalar
Returns the trace (the sum of the diagonal elements) of a square matrix or sym, m.
Examples
matrix m1 = @mnrnd(10, 10)
scalar sc1 = @trace(m1)
scalar sc2 = @sum(@getmaindiaginal(m1))
generate a random matrix, and then compute the trace directly and indirectly.
Similarly,
matrix s1 = @inner(@mnrnd(100, 20))
scalar sc1a = @trace(s1)
scalar sc2a = @sum(@getmaindiagonal(s1))
generate a random sym, and then compute the trace in two ways.
Cross-references