ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
LUDecomposition Class Reference
+ Collaboration diagram for LUDecomposition:

Public Member Functions

 __construct ($A)
 LU Decomposition constructor.
 getL ()
 Get lower triangular factor.
 getU ()
 Get upper triangular factor.
 getPivot ()
 Return pivot permutation vector.
 getDoublePivot ()
 Alias for getPivot.
 isNonsingular ()
 Is the matrix nonsingular?
 det ()
 Count determinants.
 solve ($B)
 Solve A*X = B.

Private Attributes

 $LU = array()
 $m
 $n
 $pivsign
 $piv = array()

Detailed Description

Definition at line 21 of file LUDecomposition.php.

Constructor & Destructor Documentation

LUDecomposition::__construct (   $A)

LU Decomposition constructor.

Parameters
$ARectangular matrix
Returns
Structure to access L, U and piv.

Definition at line 60 of file LUDecomposition.php.

References $m, $n, $t, ArgumentTypeException, JAMAError(), and n.

{
if ($A instanceof Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; ++$i) {
$this->piv[$i] = $i;
}
$this->pivsign = 1;
$LUrowi = $LUcolj = array();
// Outer loop.
for ($j = 0; $j < $this->n; ++$j) {
// Make a copy of the j-th column to localize references.
for ($i = 0; $i < $this->m; ++$i) {
$LUcolj[$i] = &$this->LU[$i][$j];
}
// Apply previous transformations.
for ($i = 0; $i < $this->m; ++$i) {
$LUrowi = $this->LU[$i];
// Most of the time is spent in the following dot product.
$kmax = min($i,$j);
$s = 0.0;
for ($k = 0; $k < $kmax; ++$k) {
$s += $LUrowi[$k] * $LUcolj[$k];
}
$LUrowi[$j] = $LUcolj[$i] -= $s;
}
// Find pivot and exchange if necessary.
$p = $j;
for ($i = $j+1; $i < $this->m; ++$i) {
if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
$p = $i;
}
}
if ($p != $j) {
for ($k = 0; $k < $this->n; ++$k) {
$t = $this->LU[$p][$k];
$this->LU[$p][$k] = $this->LU[$j][$k];
$this->LU[$j][$k] = $t;
}
$k = $this->piv[$p];
$this->piv[$p] = $this->piv[$j];
$this->piv[$j] = $k;
$this->pivsign = $this->pivsign * -1;
}
// Compute multipliers.
if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
for ($i = $j+1; $i < $this->m; ++$i) {
$this->LU[$i][$j] /= $this->LU[$j][$j];
}
}
}
} else {
}
} // function __construct()

+ Here is the call graph for this function:

Member Function Documentation

LUDecomposition::det ( )

Count determinants.

Returns
array d matrix deterninat

Definition at line 200 of file LUDecomposition.php.

References $d, $n, $pivsign, JAMAError(), MatrixDimensionException, and n.

{
if ($this->m == $this->n) {
for ($j = 0; $j < $this->n; ++$j) {
$d *= $this->LU[$j][$j];
}
return $d;
} else {
}
} // function det()

+ Here is the call graph for this function:

LUDecomposition::getDoublePivot ( )

Alias for getPivot.

See Also
getPivot

Definition at line 175 of file LUDecomposition.php.

References getPivot().

{
return $this->getPivot();
} // function getDoublePivot()

+ Here is the call graph for this function:

LUDecomposition::getL ( )

Get lower triangular factor.

Returns
array Lower triangular factor

Definition at line 125 of file LUDecomposition.php.

References $m, $n, and elseif().

{
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) {
$L[$i][$j] = $this->LU[$i][$j];
} elseif ($i == $j) {
$L[$i][$j] = 1.0;
} else {
$L[$i][$j] = 0.0;
}
}
}
return new Matrix($L);
} // function getL()

+ Here is the call graph for this function:

LUDecomposition::getPivot ( )

Return pivot permutation vector.

Returns
array Pivot vector

Definition at line 165 of file LUDecomposition.php.

References $piv.

Referenced by getDoublePivot().

{
return $this->piv;
} // function getPivot()

+ Here is the caller graph for this function:

LUDecomposition::getU ( )

Get upper triangular factor.

Returns
array Upper triangular factor

Definition at line 146 of file LUDecomposition.php.

References $n.

{
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) {
$U[$i][$j] = $this->LU[$i][$j];
} else {
$U[$i][$j] = 0.0;
}
}
}
return new Matrix($U);
} // function getU()
LUDecomposition::isNonsingular ( )

Is the matrix nonsingular?

Returns
true if U, and hence A, is nonsingular.

Definition at line 185 of file LUDecomposition.php.

References $n.

Referenced by solve().

{
for ($j = 0; $j < $this->n; ++$j) {
if ($this->LU[$j][$j] == 0) {
return false;
}
}
return true;
} // function isNonsingular()

+ Here is the caller graph for this function:

LUDecomposition::solve (   $B)

Solve A*X = B.

Parameters
$BA Matrix with as many rows as A and any number of columns.
Returns
X so that L*U*X = B(piv,:)
Exceptions
IllegalArgumentExceptionMatrix row dimensions must agree.
RuntimeExceptionMatrix is singular.

Definition at line 221 of file LUDecomposition.php.

References $m, $n, $X, isNonsingular(), JAMAError(), and MatrixSingularException.

{
if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) {
// Copy right hand side with pivoting
$nx = $B->getColumnDimension();
$X = $B->getMatrix($this->piv, 0, $nx-1);
// Solve L*Y = B(piv,:)
for ($k = 0; $k < $this->n; ++$k) {
for ($i = $k+1; $i < $this->n; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
// Solve U*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$k][$j] /= $this->LU[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
return $X;
} else {
}
} else {
throw new Exception(JAMAError(MatrixSquareException));
}
} // function solve()

+ Here is the call graph for this function:

Field Documentation

LUDecomposition::$LU = array()
private

Definition at line 27 of file LUDecomposition.php.

LUDecomposition::$m
private

Definition at line 33 of file LUDecomposition.php.

Referenced by __construct(), getL(), and solve().

LUDecomposition::$n
private

Definition at line 39 of file LUDecomposition.php.

Referenced by __construct(), det(), getL(), getU(), isNonsingular(), and solve().

LUDecomposition::$piv = array()
private

Definition at line 51 of file LUDecomposition.php.

Referenced by getPivot().

LUDecomposition::$pivsign
private

Definition at line 45 of file LUDecomposition.php.

Referenced by det().


The documentation for this class was generated from the following file: