本文整理匯總了PHP中Matrix::times方法的典型用法代碼示例。如果您正苦於以下問題:PHP Matrix::times方法的具體用法?PHP Matrix::times怎麽用?PHP Matrix::times使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Matrix
的用法示例。
在下文中一共展示了Matrix::times方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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 self::$_errorCodes['value'];
}
$matrixAData[$rowA][$columnA] = $matrixCell;
++$columnA;
}
++$rowA;
}
try {
$matrixA = new Matrix($matrixAData);
$rowB = 0;
foreach ($matrixData2 as $matrixRow) {
$columnB = 0;
foreach ($matrixRow as $matrixCell) {
if (is_string($matrixCell) || $matrixCell === null) {
return self::$_errorCodes['value'];
}
$matrixBData[$rowB][$columnB] = $matrixCell;
++$columnB;
}
++$rowB;
}
$matrixB = new Matrix($matrixBData);
if ($rowA != $columnB || $rowB != $columnA) {
return self::$_errorCodes['value'];
}
return $matrixA->times($matrixB)->getArray();
} catch (Exception $ex) {
return self::$_errorCodes['value'];
}
}
示例2: TestMatrix
//.........這裏部分代碼省略.........
if ($this->checkMatrices($A->transpose(), $T)) {
$this->try_success("Transpose check...");
} else {
$errorCount = $this->try_failure($errorCount, "Transpose check...", "Matrices are not equal");
}
if ($this->checkScalars($A->norm1(), $columnsummax)) {
$this->try_success("Maximum column sum...");
} else {
$errorCount = $this->try_failure($errorCount, "Maximum column sum...", "Incorrect: " . $A->norm1() . " != " . $columnsummax);
}
if ($this->checkScalars($A->normInf(), $rowsummax)) {
$this->try_success("Maximum row sum...");
} else {
$errorCount = $this->try_failure($errorCount, "Maximum row sum...", "Incorrect: " . $A->normInf() . " != " . $rowsummax);
}
if ($this->checkScalars($A->normF(), sqrt($sumofsquares))) {
$this->try_success("Frobenius norm...");
} else {
$errorCount = $this->try_failure($errorCount, "Frobenius norm...", "Incorrect:" . $A->normF() . " != " . sqrt($sumofsquares));
}
if ($this->checkScalars($A->trace(), $sumofdiagonals)) {
$this->try_success("Matrix trace...");
} else {
$errorCount = $this->try_failure($errorCount, "Matrix trace...", "Incorrect: " . $A->trace() . " != " . $sumofdiagonals);
}
$B = $A->getMatrix(0, $A->getRowDimension(), 0, $A->getRowDimension());
if ($B->det() == 0) {
$this->try_success("Matrix determinant...");
} else {
$errorCount = $this->try_failure($errorCount, "Matrix determinant...", "Incorrect: " . $B->det() . " != " . 0);
}
$A = new Matrix($columnwise, 3);
$SQ = new Matrix($square);
if ($this->checkMatrices($SQ, $A->times($A->transpose()))) {
$this->try_success("times(Matrix)...");
} else {
$errorCount = $this->try_failure($errorCount, "times(Matrix)...", "Unable to multiply matrices");
$SQ->toHTML();
$AT->toHTML();
}
$A = new Matrix($columnwise, 4);
$QR = $A->qr();
$R = $QR->getR();
$Q = $QR->getQ();
if ($this->checkMatrices($A, $Q->times($R))) {
$this->try_success("QRDecomposition...", "");
} else {
$errorCount = $this->try_failure($errorCount, "QRDecomposition...", "incorrect qr decomposition calculation");
}
$A = new Matrix($columnwise, 4);
$SVD = $A->svd();
$U = $SVD->getU();
$S = $SVD->getS();
$V = $SVD->getV();
if ($this->checkMatrices($A, $U->times($S->times($V->transpose())))) {
$this->try_success("SingularValueDecomposition...", "");
} else {
$errorCount = $this->try_failure($errorCount, "SingularValueDecomposition...", "incorrect singular value decomposition calculation");
}
$n = $A->getColumnDimension();
$A = $A->getMatrix(0, $n - 1, 0, $n - 1);
$A->set(0, 0, 0.0);
$LU = $A->lu();
$L = $LU->getL();
if ($this->checkMatrices($A->getMatrix($LU->getPivot(), 0, $n - 1), $L->times($LU->getU()))) {
$this->try_success("LUDecomposition...", "");