Method: Matrix#trace
- Defined in:
- lib/openc3/core_ext/matrix.rb
#trace ⇒ Object
Sums the diagonal values of the matrix
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/openc3/core_ext/matrix.rb', line 86 def trace sum = 0.0 @rows.length.times do |index| value = @rows[index][index] if not value.nil? sum += value else break end end return sum end |