trace method
The trace of a square matrix A
, denoted tr(A)
, is defined to be the
sum of elements on the main diagonal (from the upper left to the lower
right).
Implementation
@override
Complex trace() {
if (!isSquareMatrix) {
throw const MatrixException('The matrix is not square!');
}
// The trace value
var trace = const Complex.zero();
// Computing the trace
for (var i = 0; i < columnCount; ++i) {
trace += this(i, i);
}
return trace;
}