ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
PHPExcel_Shared_JAMA_LUDecomposition Class Reference
+ Collaboration diagram for PHPExcel_Shared_JAMA_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.

Data Fields

const MatrixSingularException = "Can only perform operation on singular matrix."
const MatrixSquareException = "Mismatched Row dimension"

Private Attributes

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

Detailed Description

Definition at line 21 of file LUDecomposition.php.

Constructor & Destructor Documentation

PHPExcel_Shared_JAMA_LUDecomposition::__construct (   $A)

LU Decomposition constructor.

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

Definition at line 63 of file LUDecomposition.php.

References $m, $n, $t, PHPExcel_Shared_JAMA_Matrix\ArgumentTypeException, and n.

{
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArray();
$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()

Member Function Documentation

PHPExcel_Shared_JAMA_LUDecomposition::det ( )

Count determinants.

Returns
array d matrix deterninat

Definition at line 203 of file LUDecomposition.php.

References $d, $n, $pivsign, PHPExcel_Shared_JAMA_Matrix\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()
PHPExcel_Shared_JAMA_LUDecomposition::getDoublePivot ( )

Alias for getPivot.

See Also
getPivot

Definition at line 178 of file LUDecomposition.php.

References getPivot().

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

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_LUDecomposition::getL ( )

Get lower triangular factor.

Returns
array Lower triangular factor

Definition at line 128 of file LUDecomposition.php.

References $m, and $n.

{
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;
}
}
}
} // function getL()
PHPExcel_Shared_JAMA_LUDecomposition::getPivot ( )

Return pivot permutation vector.

Returns
array Pivot vector

Definition at line 168 of file LUDecomposition.php.

References $piv.

Referenced by getDoublePivot().

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

+ Here is the caller graph for this function:

PHPExcel_Shared_JAMA_LUDecomposition::getU ( )

Get upper triangular factor.

Returns
array Upper triangular factor

Definition at line 149 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;
}
}
}
} // function getU()
PHPExcel_Shared_JAMA_LUDecomposition::isNonsingular ( )

Is the matrix nonsingular?

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

Definition at line 188 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:

PHPExcel_Shared_JAMA_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 224 of file LUDecomposition.php.

References $m, $n, $X, isNonsingular(), 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(self::MatrixSquareException);
}
} // function solve()

+ Here is the call graph for this function:

Field Documentation

PHPExcel_Shared_JAMA_LUDecomposition::$LU = array()
private

Definition at line 30 of file LUDecomposition.php.

PHPExcel_Shared_JAMA_LUDecomposition::$m
private

Definition at line 36 of file LUDecomposition.php.

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

PHPExcel_Shared_JAMA_LUDecomposition::$n
private

Definition at line 42 of file LUDecomposition.php.

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

PHPExcel_Shared_JAMA_LUDecomposition::$piv = array()
private

Definition at line 54 of file LUDecomposition.php.

Referenced by getPivot().

PHPExcel_Shared_JAMA_LUDecomposition::$pivsign
private

Definition at line 48 of file LUDecomposition.php.

Referenced by det().

const PHPExcel_Shared_JAMA_LUDecomposition::MatrixSingularException = "Can only perform operation on singular matrix."

Definition at line 23 of file LUDecomposition.php.

const PHPExcel_Shared_JAMA_LUDecomposition::MatrixSquareException = "Mismatched Row dimension"

Definition at line 24 of file LUDecomposition.php.


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