1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- <?php
- if (!defined('PHPEXCEL_ROOT')) {
-
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
- }
- class PHPExcel_Shared_JAMA_Matrix {
- const PolymorphicArgumentException = "Invalid argument pattern for polymorphic function.";
- const ArgumentTypeException = "Invalid argument type.";
- const ArgumentBoundsException = "Invalid argument range.";
- const MatrixDimensionException = "Matrix dimensions are not equal.";
- const ArrayLengthException = "Array length must be a multiple of m.";
-
- public $A = array();
-
- private $m;
-
- private $n;
-
- public function __construct() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
-
- case 'array':
- $this->m = count($args[0]);
- $this->n = count($args[0][0]);
- $this->A = $args[0];
- break;
-
- case 'integer':
- $this->m = $args[0];
- $this->n = $args[0];
- $this->A = array_fill(0, $this->m, array_fill(0, $this->n, 0));
- break;
-
- case 'integer,integer':
- $this->m = $args[0];
- $this->n = $args[1];
- $this->A = array_fill(0, $this->m, array_fill(0, $this->n, 0));
- break;
-
- case 'array,integer':
- $this->m = $args[1];
- if ($this->m != 0) {
- $this->n = count($args[0]) / $this->m;
- } else {
- $this->n = 0;
- }
- if (($this->m * $this->n) == count($args[0])) {
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $this->A[$i][$j] = $args[0][$i + $j * $this->m];
- }
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::ArrayLengthException);
- }
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function getArray() {
- return $this->A;
- }
-
- public function getRowDimension() {
- return $this->m;
- }
-
- public function getColumnDimension() {
- return $this->n;
- }
-
- public function get($i = null, $j = null) {
- return $this->A[$i][$j];
- }
-
- public function getMatrix() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
-
- case 'integer,integer':
- list($i0, $j0) = $args;
- if ($i0 >= 0) { $m = $this->m - $i0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- if ($j0 >= 0) { $n = $this->n - $j0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- $R = new PHPExcel_Shared_JAMA_Matrix($m, $n);
- for($i = $i0; $i < $this->m; ++$i) {
- for($j = $j0; $j < $this->n; ++$j) {
- $R->set($i, $j, $this->A[$i][$j]);
- }
- }
- return $R;
- break;
-
- case 'integer,integer,integer,integer':
- list($i0, $iF, $j0, $jF) = $args;
- if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- if (($jF > $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- $R = new PHPExcel_Shared_JAMA_Matrix($m+1, $n+1);
- for($i = $i0; $i <= $iF; ++$i) {
- for($j = $j0; $j <= $jF; ++$j) {
- $R->set($i - $i0, $j - $j0, $this->A[$i][$j]);
- }
- }
- return $R;
- break;
-
- case 'array,array':
- list($RL, $CL) = $args;
- if (count($RL) > 0) { $m = count($RL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- if (count($CL) > 0) { $n = count($CL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- $R = new PHPExcel_Shared_JAMA_Matrix($m, $n);
- for($i = 0; $i < $m; ++$i) {
- for($j = 0; $j < $n; ++$j) {
- $R->set($i - $i0, $j - $j0, $this->A[$RL[$i]][$CL[$j]]);
- }
- }
- return $R;
- break;
-
- case 'array,array':
- list($RL, $CL) = $args;
- if (count($RL) > 0) { $m = count($RL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- if (count($CL) > 0) { $n = count($CL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- $R = new PHPExcel_Shared_JAMA_Matrix($m, $n);
- for($i = 0; $i < $m; ++$i) {
- for($j = 0; $j < $n; ++$j) {
- $R->set($i, $j, $this->A[$RL[$i]][$CL[$j]]);
- }
- }
- return $R;
- break;
-
- case 'integer,integer,array':
- list($i0, $iF, $CL) = $args;
- if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- if (count($CL) > 0) { $n = count($CL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- $R = new PHPExcel_Shared_JAMA_Matrix($m, $n);
- for($i = $i0; $i < $iF; ++$i) {
- for($j = 0; $j < $n; ++$j) {
- $R->set($i - $i0, $j, $this->A[$RL[$i]][$j]);
- }
- }
- return $R;
- break;
-
- case 'array,integer,integer':
- list($RL, $j0, $jF) = $args;
- if (count($RL) > 0) { $m = count($RL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- if (($jF >= $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
- $R = new PHPExcel_Shared_JAMA_Matrix($m, $n+1);
- for($i = 0; $i < $m; ++$i) {
- for($j = $j0; $j <= $jF; ++$j) {
- $R->set($i, $j - $j0, $this->A[$RL[$i]][$j]);
- }
- }
- return $R;
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function checkMatrixDimensions($B = null) {
- if ($B instanceof PHPExcel_Shared_JAMA_Matrix) {
- if (($this->m == $B->getRowDimension()) && ($this->n == $B->getColumnDimension())) {
- return true;
- } else {
- throw new PHPExcel_Calculation_Exception(self::MatrixDimensionException);
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
- }
- }
-
- public function set($i = null, $j = null, $c = null) {
-
- $this->A[$i][$j] = $c;
- }
-
- public function identity($m = null, $n = null) {
- return $this->diagonal($m, $n, 1);
- }
-
- 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;
- }
-
- public function getMatrixByRow($i0 = null, $iF = null) {
- if (is_int($i0)) {
- if (is_int($iF)) {
- return $this->getMatrix($i0, 0, $iF + 1, $this->n);
- } else {
- return $this->getMatrix($i0, 0, $i0 + 1, $this->n);
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
- }
- }
-
- public function getMatrixByCol($j0 = null, $jF = null) {
- if (is_int($j0)) {
- if (is_int($jF)) {
- return $this->getMatrix(0, $j0, $this->m, $jF + 1);
- } else {
- return $this->getMatrix(0, $j0, $this->m, $j0 + 1);
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
- }
- }
-
- 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;
- }
-
- public function trace() {
- $s = 0;
- $n = min($this->m, $this->n);
- for($i = 0; $i < $n; ++$i) {
- $s += $this->A[$i][$i];
- }
- return $s;
- }
-
- public function uminus() {
- }
-
- public function plus() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $M->set($i, $j, $M->get($i, $j) + $this->A[$i][$j]);
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function plusEquals() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $validValues = True;
- $value = $M->get($i, $j);
- if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
- $this->A[$i][$j] = trim($this->A[$i][$j],'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
- }
- if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
- $value = trim($value,'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($value);
- }
- if ($validValues) {
- $this->A[$i][$j] += $value;
- } else {
- $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
- }
- }
- }
- return $this;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function minus() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $M->set($i, $j, $M->get($i, $j) - $this->A[$i][$j]);
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function minusEquals() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $validValues = True;
- $value = $M->get($i, $j);
- if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
- $this->A[$i][$j] = trim($this->A[$i][$j],'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
- }
- if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
- $value = trim($value,'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($value);
- }
- if ($validValues) {
- $this->A[$i][$j] -= $value;
- } else {
- $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
- }
- }
- }
- return $this;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function arrayTimes() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $M->set($i, $j, $M->get($i, $j) * $this->A[$i][$j]);
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function arrayTimesEquals() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $validValues = True;
- $value = $M->get($i, $j);
- if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
- $this->A[$i][$j] = trim($this->A[$i][$j],'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
- }
- if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
- $value = trim($value,'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($value);
- }
- if ($validValues) {
- $this->A[$i][$j] *= $value;
- } else {
- $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
- }
- }
- }
- return $this;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function arrayRightDivide() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $validValues = True;
- $value = $M->get($i, $j);
- if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
- $this->A[$i][$j] = trim($this->A[$i][$j],'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
- }
- if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
- $value = trim($value,'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($value);
- }
- if ($validValues) {
- if ($value == 0) {
-
- $M->set($i, $j, '#DIV/0!');
- } else {
- $M->set($i, $j, $this->A[$i][$j] / $value);
- }
- } else {
- $M->set($i, $j, PHPExcel_Calculation_Functions::NaN());
- }
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function arrayRightDivideEquals() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $this->A[$i][$j] = $this->A[$i][$j] / $M->get($i, $j);
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function arrayLeftDivide() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $M->set($i, $j, $M->get($i, $j) / $this->A[$i][$j]);
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function arrayLeftDivideEquals() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $this->A[$i][$j] = $M->get($i, $j) / $this->A[$i][$j];
- }
- }
- return $M;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function times() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $B = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- if ($this->n == $B->m) {
- $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
- for($j = 0; $j < $B->n; ++$j) {
- for ($k = 0; $k < $this->n; ++$k) {
- $Bcolj[$k] = $B->A[$k][$j];
- }
- for($i = 0; $i < $this->m; ++$i) {
- $Arowi = $this->A[$i];
- $s = 0;
- for($k = 0; $k < $this->n; ++$k) {
- $s += $Arowi[$k] * $Bcolj[$k];
- }
- $C->A[$i][$j] = $s;
- }
- }
- return $C;
- } else {
- throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionMismatch));
- }
- break;
- case 'array':
- $B = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- if ($this->n == $B->m) {
- $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
- for($i = 0; $i < $C->m; ++$i) {
- for($j = 0; $j < $C->n; ++$j) {
- $s = "0";
- for($k = 0; $k < $C->n; ++$k) {
- $s += $this->A[$i][$k] * $B->A[$k][$j];
- }
- $C->A[$i][$j] = $s;
- }
- }
- return $C;
- } else {
- throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionMismatch));
- }
- return $M;
- break;
- case 'integer':
- $C = new PHPExcel_Shared_JAMA_Matrix($this->A);
- for($i = 0; $i < $C->m; ++$i) {
- for($j = 0; $j < $C->n; ++$j) {
- $C->A[$i][$j] *= $args[0];
- }
- }
- return $C;
- break;
- case 'double':
- $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $this->n);
- for($i = 0; $i < $C->m; ++$i) {
- for($j = 0; $j < $C->n; ++$j) {
- $C->A[$i][$j] = $args[0] * $this->A[$i][$j];
- }
- }
- return $C;
- break;
- case 'float':
- $C = new PHPExcel_Shared_JAMA_Matrix($this->A);
- for($i = 0; $i < $C->m; ++$i) {
- for($j = 0; $j < $C->n; ++$j) {
- $C->A[$i][$j] *= $args[0];
- }
- }
- return $C;
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function power() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- break;
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $validValues = True;
- $value = $M->get($i, $j);
- if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
- $this->A[$i][$j] = trim($this->A[$i][$j],'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
- }
- if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
- $value = trim($value,'"');
- $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($value);
- }
- if ($validValues) {
- $this->A[$i][$j] = pow($this->A[$i][$j],$value);
- } else {
- $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
- }
- }
- }
- return $this;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function concat() {
- if (func_num_args() > 0) {
- $args = func_get_args();
- $match = implode(",", array_map('gettype', $args));
- switch($match) {
- case 'object':
- if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
- case 'array':
- $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
- break;
- default:
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- break;
- }
- $this->checkMatrixDimensions($M);
- for($i = 0; $i < $this->m; ++$i) {
- for($j = 0; $j < $this->n; ++$j) {
- $this->A[$i][$j] = trim($this->A[$i][$j],'"').trim($M->get($i, $j),'"');
- }
- }
- return $this;
- } else {
- throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
- }
- }
-
- public function solve($B) {
- if ($this->m == $this->n) {
- $LU = new PHPExcel_Shared_JAMA_LUDecomposition($this);
- return $LU->solve($B);
- } else {
- $QR = new PHPExcel_Shared_JAMA_QRDecomposition($this);
- return $QR->solve($B);
- }
- }
-
- public function inverse() {
- return $this->solve($this->identity($this->m, $this->m));
- }
-
- public function det() {
- $L = new PHPExcel_Shared_JAMA_LUDecomposition($this);
- return $L->det();
- }
- }
|