public function PHPExcel_Shared_JAMA_QRDecomposition::solve in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/QRDecomposition.php \PHPExcel_Shared_JAMA_QRDecomposition::solve()
* Least squares solution of A*X = B * *
Parameters
Matrix $B A Matrix with as many rows as A and any number of columns.: * @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Shared/ JAMA/ QRDecomposition.php, line 194
Class
- PHPExcel_Shared_JAMA_QRDecomposition
- @package JAMA
Code
public function solve($B) {
if ($B
->getRowDimension() == $this->m) {
if ($this
->isFullRank()) {
// Copy right hand side
$nx = $B
->getColumnDimension();
$X = $B
->getArrayCopy();
// Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; ++$k) {
for ($j = 0; $j < $nx; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $X[$i][$j];
}
$s = -$s / $this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$X[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
// Solve R*X = Y;
for ($k = $this->n - 1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->Rdiag[$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->QR[$i][$k];
}
}
}
$X = new PHPExcel_Shared_JAMA_Matrix($X);
return $X
->getMatrix(0, $this->n - 1, 0, $nx);
}
else {
throw new PHPExcel_Calculation_Exception(self::MatrixRankException);
}
}
else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
}
}