You are here

public function PHPExcel_Shared_JAMA_LUDecomposition::solve in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/LUDecomposition.php \PHPExcel_Shared_JAMA_LUDecomposition::solve()

* Solve A*X = B * *

Parameters

$B A Matrix with as many rows as A and any number of columns.: * @return X so that L*U*X = B(piv,:) * @PHPExcel_Calculation_Exception IllegalArgumentException Matrix row dimensions must agree. * @PHPExcel_Calculation_Exception RuntimeException Matrix is singular.

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/LUDecomposition.php, line 224

Class

PHPExcel_Shared_JAMA_LUDecomposition
@package JAMA

Code

public function solve($B) {
  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 {
      throw new PHPExcel_Calculation_Exception(self::MatrixSingularException);
    }
  }
  else {
    throw new PHPExcel_Calculation_Exception(self::MatrixSquareException);
  }
}