18 $this->luMatrix = $matrix->
toArray();
19 $this->rows = $matrix->
rows;
20 $this->columns = $matrix->
columns;
34 $columns = min($this->rows, $this->columns);
36 for ($column = 0; $column <
$columns; ++$column) {
38 $lower[
$row][$column] = $this->luMatrix[
$row][$column];
39 } elseif (
$row === $column) {
40 $lower[
$row][$column] = 1.0;
42 $lower[
$row][$column] = 0.0;
59 $rows = min($this->rows, $this->columns);
62 if (
$row <= $column) {
63 $upper[
$row][$column] = $this->luMatrix[
$row][$column];
65 $upper[
$row][$column] = 0.0;
83 $pivotCount = count($pivots);
85 $pMatrix[
$row] = array_fill(0, $pivotCount, 0);
89 return new Matrix($pMatrix);
110 if ($this->luMatrix[$diagonal][$diagonal] === 0.0) {
145 $luColumn[
$row] = &$this->luMatrix[
$row][$column];
154 $luRow = $this->luMatrix[
$row];
156 $kmax = min(
$row, $column);
158 for ($kValue = 0; $kValue < $kmax; ++$kValue) {
159 $sValue += $luRow[$kValue] * $luColumn[$kValue];
161 $luRow[$column] = $luColumn[
$row] -= $sValue;
165 private function findPivot($column, array $luColumn): int
169 if (abs($luColumn[
$row]) > abs($luColumn[
$pivot])) {
180 $tValue = $this->luMatrix[
$pivot][$kValue];
181 $this->luMatrix[
$pivot][$kValue] = $this->luMatrix[$column][$kValue];
182 $this->luMatrix[$column][$kValue] = $tValue;
185 $lValue = $this->pivot[
$pivot];
186 $this->pivot[
$pivot] = $this->pivot[$column];
187 $this->pivot[$column] = $lValue;
192 if (($diagonal < $this->rows) && ($this->luMatrix[$diagonal][$diagonal] != 0.0)) {
194 $this->luMatrix[
$row][$diagonal] /= $this->luMatrix[$diagonal][$diagonal];
202 foreach ($this->pivot as $rowId) {
221 if ($B->
rows !== $this->rows) {
222 throw new Exception(
'Matrix row dimensions are not equal');
225 if ($this->rows !== $this->columns) {
226 throw new Exception(
'LU solve() only works on square matrices');
230 throw new Exception(
'Can only perform operation on singular matrix');
240 for ($j = 0; $j < $nx; ++$j) {
241 $X[
$i][$j] -=
$X[$k][$j] * $this->luMatrix[
$i][$k];
247 for ($k = $this->columns - 1; $k >= 0; --$k) {
248 for ($j = 0; $j < $nx; ++$j) {
249 $X[$k][$j] /= $this->luMatrix[$k][$k];
251 for (
$i = 0;
$i < $k; ++
$i) {
252 for ($j = 0; $j < $nx; ++$j) {
253 $X[
$i][$j] -=
$X[$k][$j] * $this->luMatrix[
$i][$k];
localisedReferenceColumn($column)
pivotExchange($pivot, $column)
rows()
Returns a Generator that will yield each row of the matrix in turn as a vector matrix or the value of...
applyTransformations($column, array $luColumn)
findPivot($column, array $luColumn)
getP()
Return pivot permutation vector.
columns()
Returns a Generator that will yield each column of the matrix in turn as a vector matrix or the value...
toArray()
Return the matrix as a 2-dimensional array.
getL()
Get lower triangular factor.
isNonsingular()
Is the matrix nonsingular?
getU()
Get upper triangular factor.
__construct(Matrix $matrix)
solve(Matrix $B)
Solve A*X = B.
Class for the creating "special" Matrices.
computeMultipliers($diagonal)
getRows(int $row, int $rowCount=1)
Return a new matrix as a subset of rows from this matrix, starting at row number $row, and $rowCount rows A $rowCount value of 0 will return all rows of the matrix from $row A negative $rowCount value will return rows until that many rows from the end of the matrix.
getPivot()
Return pivot permutation vector.