18        $this->luMatrix = 
$matrix->toArray();
 
   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];
 
An exception for terminatinating execution or to throw for unit testing.
getU()
Get upper triangular factor.
applyTransformations($column, array $luColumn)
localisedReferenceColumn($column)
getP()
Return pivot permutation vector.
computeMultipliers($diagonal)
__construct(Matrix $matrix)
isNonsingular()
Is the matrix nonsingular?
getL()
Get lower triangular factor.
pivotExchange($pivot, $column)
getPivot()
Return pivot permutation vector.
solve(Matrix $B)
Solve A*X = B.
findPivot($column, array $luColumn)
getRows(int $row, int $rowCount=1)
Return a new matrix as a subset of rows from this matrix, starting at row number $row,...
rows()
Returns a Generator that will yield each row of the matrix in turn as a vector matrix or the value of...
columns()
Returns a Generator that will yield each column of the matrix in turn as a vector matrix or the value...
Class for the creating "special" Matrices.