You are here

public static function PHPExcel_Calculation_MathTrig::MINVERSE in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php \PHPExcel_Calculation_MathTrig::MINVERSE()

* MINVERSE * * Returns the inverse matrix for the matrix stored in an array. * * Excel Function: * MINVERSE(array) * * @access public * @category Mathematical and Trigonometric Functions *

Parameters

array $matrixValues A matrix of values: * @return array

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php, line 571

Class

PHPExcel_Calculation_MathTrig
PHPExcel_Calculation_MathTrig

Code

public static function MINVERSE($matrixValues) {
  $matrixData = array();
  if (!is_array($matrixValues)) {
    $matrixValues = array(
      array(
        $matrixValues,
      ),
    );
  }
  $row = $maxColumn = 0;
  foreach ($matrixValues as $matrixRow) {
    if (!is_array($matrixRow)) {
      $matrixRow = array(
        $matrixRow,
      );
    }
    $column = 0;
    foreach ($matrixRow as $matrixCell) {
      if (is_string($matrixCell) || $matrixCell === null) {
        return PHPExcel_Calculation_Functions::VALUE();
      }
      $matrixData[$column][$row] = $matrixCell;
      ++$column;
    }
    if ($column > $maxColumn) {
      $maxColumn = $column;
    }
    ++$row;
  }
  if ($row != $maxColumn) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  try {
    $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData);
    return $matrix
      ->inverse()
      ->getArray();
  } catch (PHPExcel_Exception $ex) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
}