本文整理汇总了PHP中PHPExcel_Shared_JAMA_Matrix类的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_JAMA_Matrix类的具体用法?PHP PHPExcel_Shared_JAMA_Matrix怎么用?PHP PHPExcel_Shared_JAMA_Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPExcel_Shared_JAMA_Matrix类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _processTokenStack
//.........这里部分代码省略.........
break;
case '-':
// Subtraction
$this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'minusEquals', $stack);
break;
case '*':
// Multiplication
$this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayTimesEquals', $stack);
break;
case '/':
// Division
$this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayRightDivide', $stack);
break;
case '^':
// Exponential
$this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'power', $stack);
break;
case '&':
// Concatenation
// If either of the operands is a matrix, we need to treat them both as matrices
// (converting the other operand to a matrix if need be); then perform the required
// matrix operation
if (is_bool($operand1)) {
$operand1 = $operand1 ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
}
if (is_bool($operand2)) {
$operand2 = $operand2 ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
}
if (is_array($operand1) || is_array($operand2)) {
// Ensure that both operands are arrays/matrices
self::_checkMatrixOperands($operand1, $operand2, 2);
try {
// Convert operand 1 from a PHP array to a matrix
$matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);
// Perform the required operation against the operand 1 matrix, passing in operand 2
$matrixResult = $matrix->concat($operand2);
$result = $matrixResult->getArray();
} catch (PHPExcel_Exception $ex) {
$this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
$result = '#VALUE!';
}
} else {
$result = '"' . str_replace('""', '"', self::_unwrapResult($operand1, '"') . self::_unwrapResult($operand2, '"')) . '"';
}
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
$stack->push('Value', $result);
break;
case '|':
// Intersect
$rowIntersect = array_intersect_key($operand1, $operand2);
$cellIntersect = $oCol = $oRow = array();
foreach (array_keys($rowIntersect) as $row) {
$oRow[] = $row;
foreach ($rowIntersect[$row] as $col => $data) {
$oCol[] = PHPExcel_Cell::columnIndexFromString($col) - 1;
$cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]);
}
}
$cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . PHPExcel_Cell::stringFromColumnIndex(max($oCol)) . max($oRow);
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($cellIntersect));
$stack->push('Value', $cellIntersect, $cellRef);
break;
}
// if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
} elseif ($token === '~' || $token === '%') {
// echo 'Token is a unary operator<br />';
示例2: transpose
/**
* transpose
*
* Tranpose matrix
* @return Matrix Transposed matrix
*/
public function transpose()
{
$R = new PHPExcel_Shared_JAMA_Matrix($this->n, $this->m);
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
$R->set($j, $i, $this->A[$i][$j]);
}
}
return $R;
}
示例3: MMULT
/**
* MMULT
*
* @param array $matrixData1 A matrix of values
* @param array $matrixData2 A matrix of values
* @return array
*/
public static function MMULT($matrixData1, $matrixData2)
{
$matrixAData = $matrixBData = array();
if (!is_array($matrixData1)) {
$matrixData1 = array(array($matrixData1));
}
if (!is_array($matrixData2)) {
$matrixData2 = array(array($matrixData2));
}
try {
$rowA = 0;
foreach ($matrixData1 as $matrixRow) {
if (!is_array($matrixRow)) {
$matrixRow = array($matrixRow);
}
$columnA = 0;
foreach ($matrixRow as $matrixCell) {
if (!is_numeric($matrixCell) || $matrixCell === null) {
return PHPExcel_Calculation_Functions::VALUE();
}
$matrixAData[$rowA][$columnA] = $matrixCell;
++$columnA;
}
++$rowA;
}
$matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData);
$rowB = 0;
foreach ($matrixData2 as $matrixRow) {
if (!is_array($matrixRow)) {
$matrixRow = array($matrixRow);
}
$columnB = 0;
foreach ($matrixRow as $matrixCell) {
if (!is_numeric($matrixCell) || $matrixCell === null) {
return PHPExcel_Calculation_Functions::VALUE();
}
$matrixBData[$rowB][$columnB] = $matrixCell;
++$columnB;
}
++$rowB;
}
$matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData);
if ($columnA != $rowB) {
return PHPExcel_Calculation_Functions::VALUE();
}
return $matrixA->times($matrixB)->getArray();
} catch (PHPExcel_Exception $ex) {
var_dump($ex->getMessage());
return PHPExcel_Calculation_Functions::VALUE();
}
}
示例4: solve
/**
* Least squares solution of A*X = B
*
* @param 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.
*/
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 Exception(self::MatrixRankException);
}
} else {
throw new Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
}
}
示例5: diagonal
/**
* diagonal
*
* Generate a diagonal matrix
*
* @param int $m Row dimension
* @param int $n Column dimension
* @param mixed $c Diagonal value
*
* @return Matrix Diagonal matrix
*/
public function diagonal($m = null, $n = null, $c = 1)
{
$R = new PHPExcel_Shared_JAMA_Matrix($m, $n);
for ($i = 0; $i < $m; ++$i) {
$R->set($i, $i, $c);
}
return $R;
}
示例6: MMULT
/**
* MMULT
*
* @param array $matrixData1 A matrix of values
* @param array $matrixData2 A matrix of values
* @return array
*/
public static function MMULT($matrixData1, $matrixData2)
{
$matrixAData = $matrixBData = array();
if (!is_array($matrixData1)) {
$matrixData1 = array(array($matrixData1));
}
if (!is_array($matrixData2)) {
$matrixData2 = array(array($matrixData2));
}
$rowA = 0;
foreach ($matrixData1 as $matrixRow) {
$columnA = 0;
foreach ($matrixRow as $matrixCell) {
if (is_string($matrixCell) || $matrixCell === null) {
return PHPExcel_Calculation_Functions::VALUE();
}
$matrixAData[$rowA][$columnA] = $matrixCell;
++$columnA;
}
++$rowA;
}
try {
$matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData);
$rowB = 0;
foreach ($matrixData2 as $matrixRow) {
$columnB = 0;
foreach ($matrixRow as $matrixCell) {
if (is_string($matrixCell) || $matrixCell === null) {
return PHPExcel_Calculation_Functions::VALUE();
}
$matrixBData[$rowB][$columnB] = $matrixCell;
++$columnB;
}
++$rowB;
}
$matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData);
if ($rowA != $columnB || $rowB != $columnA) {
return PHPExcel_Calculation_Functions::VALUE();
}
return $matrixA->times($matrixB)->getArray();
} catch (Exception $ex) {
return PHPExcel_Calculation_Functions::VALUE();
}
}