private static function getDeterminant(Matrix $matrix)
    {
        $dimensions = $matrix->rows;
        if ($dimensions == 1) {
            return $matrix->getValue(1, 1);
        } elseif ($dimensions == 2) {
            return $matrix->getValue(1, 1) * $matrix->getValue(2, 2) - $matrix->getValue(1, 2) * $matrix->getValue(2, 1);
        }
        
        $determinant = 0;
        for ($i = 1; $i <= $dimensions; ++$i) {
            $det = $matrix->getValue(1, $i) * self::getDeterminantSegment($matrix, 0, $i-1);
            if (($i % 2) == 0) {
                $determinant -= $det;
            } else {
                $determinant += $det;
            }
        }

        return $determinant;
    }