27 private $LU = array();
61 if ($A instanceof
Matrix) {
63 $this->LU = $A->getArrayCopy();
64 $this->m = $A->getRowDimension();
65 $this->
n = $A->getColumnDimension();
70 $LUrowi = $LUcolj = array();
76 $LUcolj[$i] = &$this->LU[$i][$j];
80 $LUrowi = $this->LU[$i];
84 for ($k = 0; $k < $kmax; ++$k) {
85 $s += $LUrowi[$k] * $LUcolj[$k];
87 $LUrowi[$j] = $LUcolj[$i] -= $s;
91 for ($i = $j+1; $i <
$this->m; ++$i) {
92 if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
98 $t = $this->LU[$p][$k];
99 $this->LU[$p][$k] = $this->LU[$j][$k];
100 $this->LU[$j][$k] =
$t;
103 $this->piv[$p] = $this->piv[$j];
105 $this->pivsign = $this->pivsign * -1;
108 if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
109 for ($i = $j+1; $i <
$this->m; ++$i) {
110 $this->LU[$i][$j] /= $this->LU[$j][$j];
129 $L[$i][$j] = $this->LU[$i][$j];
150 $U[$i][$j] = $this->LU[$i][$j];
187 if ($this->LU[$j][$j] == 0) {
201 if ($this->m == $this->
n) {
204 $d *= $this->LU[$j][$j];
222 if ($B->getRowDimension() ==
$this->m) {
225 $nx = $B->getColumnDimension();
226 $X = $B->getMatrix($this->piv, 0, $nx-1);
229 for ($i = $k+1; $i <
$this->n; ++$i) {
230 for ($j = 0; $j < $nx; ++$j) {
231 $X->A[$i][$j] -=
$X->A[$k][$j] * $this->LU[$i][$k];
236 for ($k = $this->n-1; $k >= 0; --$k) {
237 for ($j = 0; $j < $nx; ++$j) {
238 $X->A[$k][$j] /= $this->LU[$k][$k];
240 for ($i = 0; $i < $k; ++$i) {
241 for ($j = 0; $j < $nx; ++$j) {
242 $X->A[$i][$j] -=
$X->A[$k][$j] * $this->LU[$i][$k];