public function trace() : float { $this->checkSquare(); $trace = 0; for ($i = 0, $rows = $this->getRowCount(); $i < $rows; $i++) { $trace += $this->get($i, $i); } return $trace; }
public function testTrace() { $matrix = new Matrix([[1, 2, 3], [0, 1, 4], [5, 6, 0]]); static::assertEquals(2, $matrix->trace()); }