We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 088e28f commit a904f9cCopy full SHA for a904f9c
src/Matrix.php
@@ -150,6 +150,25 @@ public function determinant()
150
return $this->getLUDecomp()->determinant();
151
}
152
153
+ /**
154
+ * diagonal
155
+ *
156
+ * Returns the diagonal of this matrix as a vector.
157
158
+ * @return self
159
+ */
160
+ public function diagonal()
161
+ {
162
+ $diagonal = [];
163
+ $max = min([$this->rows, $this->columns]);
164
+
165
+ for ($i = 0; $i < $max; $i++) {
166
+ $diagonal[] = $this->get($i, $i);
167
+ }
168
169
+ return new static([$diagonal]);
170
171
172
/**
173
* equals
174
*
@@ -658,4 +677,4 @@ protected function isLiteralValid(array $literal)
658
677
659
678
return true;
660
679
661
-}
680
+}
0 commit comments