stdlib/matrix.rb
#
# Returns the trace (sum of diagonal elements) of the matrix.
#   Matrix[[7,6], [3,9]].trace
#     => 16
#
Returns the trace (sum of diagonal elements) of the matrix.
Returns the trace ( sum of diagonal elements ) of the matrix .
def trace
    Matrix.Raise ErrDimensionMismatch unless square?
    (0...column_count).inject(0) do |tr, i|
      tr + @rows[i][i]
    end
  end
def trace Matrix . Raise ErrDimensionMismatch unless square? ( 0 ... column_count ) . inject ( 0 ) do | tr , i | tr + @rows [ i ] [ i ] end end
Returns the trace (sum of diagonal elements) of the matrix.
Returns the trace ( sum of diagonal elements ) of the matrix .