ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_Shared_JAMA_LUDecomposition Class Reference
+ Collaboration diagram for PHPExcel_Shared_JAMA_LUDecomposition:

Public Member Functions

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

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

◆ __construct()

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 $i, $m, $n, $s, $t, PHPExcel_Shared_JAMA_Matrix\ArgumentTypeException, array, and n.

63  {
64  if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
65  // Use a "left-looking", dot-product, Crout/Doolittle algorithm.
66  $this->LU = $A->getArray();
67  $this->m = $A->getRowDimension();
68  $this->n = $A->getColumnDimension();
69  for ($i = 0; $i < $this->m; ++$i) {
70  $this->piv[$i] = $i;
71  }
72  $this->pivsign = 1;
73  $LUrowi = $LUcolj = array();
74 
75  // Outer loop.
76  for ($j = 0; $j < $this->n; ++$j) {
77  // Make a copy of the j-th column to localize references.
78  for ($i = 0; $i < $this->m; ++$i) {
79  $LUcolj[$i] = &$this->LU[$i][$j];
80  }
81  // Apply previous transformations.
82  for ($i = 0; $i < $this->m; ++$i) {
83  $LUrowi = $this->LU[$i];
84  // Most of the time is spent in the following dot product.
85  $kmax = min($i,$j);
86  $s = 0.0;
87  for ($k = 0; $k < $kmax; ++$k) {
88  $s += $LUrowi[$k] * $LUcolj[$k];
89  }
90  $LUrowi[$j] = $LUcolj[$i] -= $s;
91  }
92  // Find pivot and exchange if necessary.
93  $p = $j;
94  for ($i = $j+1; $i < $this->m; ++$i) {
95  if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
96  $p = $i;
97  }
98  }
99  if ($p != $j) {
100  for ($k = 0; $k < $this->n; ++$k) {
101  $t = $this->LU[$p][$k];
102  $this->LU[$p][$k] = $this->LU[$j][$k];
103  $this->LU[$j][$k] = $t;
104  }
105  $k = $this->piv[$p];
106  $this->piv[$p] = $this->piv[$j];
107  $this->piv[$j] = $k;
108  $this->pivsign = $this->pivsign * -1;
109  }
110  // Compute multipliers.
111  if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
112  for ($i = $j+1; $i < $this->m; ++$i) {
113  $this->LU[$i][$j] /= $this->LU[$j][$j];
114  }
115  }
116  }
117  } else {
119  }
120  } // function __construct()
if(! $in) print Initializing normalization quick check tables n
$s
Definition: pwgen.php:45
PHPExcel root directory.
Definition: Matrix.php:27
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19

Member Function Documentation

◆ det()

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.

203  {
204  if ($this->m == $this->n) {
205  $d = $this->pivsign;
206  for ($j = 0; $j < $this->n; ++$j) {
207  $d *= $this->LU[$j][$j];
208  }
209  return $d;
210  } else {
212  }
213  } // function det()
if(! $in) print Initializing normalization quick check tables n
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

◆ getDoublePivot()

PHPExcel_Shared_JAMA_LUDecomposition::getDoublePivot ( )

Alias for getPivot.

See also
getPivot

Definition at line 178 of file LUDecomposition.php.

References getPivot().

178  {
179  return $this->getPivot();
180  } // function getDoublePivot()
getPivot()
Return pivot permutation vector.
+ Here is the call graph for this function:

◆ getL()

PHPExcel_Shared_JAMA_LUDecomposition::getL ( )

Get lower triangular factor.

Returns
array Lower triangular factor

Definition at line 128 of file LUDecomposition.php.

References $i, $m, and $n.

128  {
129  for ($i = 0; $i < $this->m; ++$i) {
130  for ($j = 0; $j < $this->n; ++$j) {
131  if ($i > $j) {
132  $L[$i][$j] = $this->LU[$i][$j];
133  } elseif ($i == $j) {
134  $L[$i][$j] = 1.0;
135  } else {
136  $L[$i][$j] = 0.0;
137  }
138  }
139  }
140  return new PHPExcel_Shared_JAMA_Matrix($L);
141  } // function getL()
PHPExcel root directory.
Definition: Matrix.php:27
$i
Definition: disco.tpl.php:19

◆ getPivot()

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().

168  {
169  return $this->piv;
170  } // function getPivot()
+ Here is the caller graph for this function:

◆ getU()

PHPExcel_Shared_JAMA_LUDecomposition::getU ( )

Get upper triangular factor.

Returns
array Upper triangular factor

Definition at line 149 of file LUDecomposition.php.

References $i, and $n.

149  {
150  for ($i = 0; $i < $this->n; ++$i) {
151  for ($j = 0; $j < $this->n; ++$j) {
152  if ($i <= $j) {
153  $U[$i][$j] = $this->LU[$i][$j];
154  } else {
155  $U[$i][$j] = 0.0;
156  }
157  }
158  }
159  return new PHPExcel_Shared_JAMA_Matrix($U);
160  } // function getU()
PHPExcel root directory.
Definition: Matrix.php:27
$i
Definition: disco.tpl.php:19

◆ isNonsingular()

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().

188  {
189  for ($j = 0; $j < $this->n; ++$j) {
190  if ($this->LU[$j][$j] == 0) {
191  return false;
192  }
193  }
194  return true;
195  } // function isNonsingular()
+ Here is the caller graph for this function:

◆ solve()

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,:) IllegalArgumentException Matrix row dimensions must agree. RuntimeException Matrix is singular.

Definition at line 224 of file LUDecomposition.php.

References $i, $m, $n, isNonsingular(), and MatrixSingularException.

224  {
225  if ($B->getRowDimension() == $this->m) {
226  if ($this->isNonsingular()) {
227  // Copy right hand side with pivoting
228  $nx = $B->getColumnDimension();
229  $X = $B->getMatrix($this->piv, 0, $nx-1);
230  // Solve L*Y = B(piv,:)
231  for ($k = 0; $k < $this->n; ++$k) {
232  for ($i = $k+1; $i < $this->n; ++$i) {
233  for ($j = 0; $j < $nx; ++$j) {
234  $X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
235  }
236  }
237  }
238  // Solve U*X = Y;
239  for ($k = $this->n-1; $k >= 0; --$k) {
240  for ($j = 0; $j < $nx; ++$j) {
241  $X->A[$k][$j] /= $this->LU[$k][$k];
242  }
243  for ($i = 0; $i < $k; ++$i) {
244  for ($j = 0; $j < $nx; ++$j) {
245  $X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
246  }
247  }
248  }
249  return $X;
250  } else {
252  }
253  } else {
254  throw new PHPExcel_Calculation_Exception(self::MatrixSquareException);
255  }
256  } // function solve()
const MatrixSingularException
Definition: Error.php:54
isNonsingular()
Is the matrix nonsingular?
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

Field Documentation

◆ $LU

PHPExcel_Shared_JAMA_LUDecomposition::$LU = array()
private

Definition at line 30 of file LUDecomposition.php.

◆ $m

PHPExcel_Shared_JAMA_LUDecomposition::$m
private

Definition at line 36 of file LUDecomposition.php.

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

◆ $n

PHPExcel_Shared_JAMA_LUDecomposition::$n
private

Definition at line 42 of file LUDecomposition.php.

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

◆ $piv

PHPExcel_Shared_JAMA_LUDecomposition::$piv = array()
private

Definition at line 54 of file LUDecomposition.php.

Referenced by getPivot().

◆ $pivsign

PHPExcel_Shared_JAMA_LUDecomposition::$pivsign
private

Definition at line 48 of file LUDecomposition.php.

Referenced by det().

◆ MatrixSingularException

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

Definition at line 23 of file LUDecomposition.php.

◆ MatrixSquareException

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: