ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Matrix.php
Go to the documentation of this file.
1<?php
7if (!defined('PHPEXCEL_ROOT')) {
11 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
12 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
13}
14
15
16/*
17 * Matrix class
18 *
19 * @author Paul Meagher
20 * @author Michael Bommarito
21 * @author Lukasz Karapuda
22 * @author Bartek Matosiuk
23 * @version 1.8
24 * @license PHP v3.0
25 * @see http://math.nist.gov/javanumerics/jama/
26 */
28
29
30 const PolymorphicArgumentException = "Invalid argument pattern for polymorphic function.";
31 const ArgumentTypeException = "Invalid argument type.";
32 const ArgumentBoundsException = "Invalid argument range.";
33 const MatrixDimensionException = "Matrix dimensions are not equal.";
34 const ArrayLengthException = "Array length must be a multiple of m.";
35
42 public $A = array();
43
50 private $m;
51
58 private $n;
59
60
66 public function __construct() {
67 if (func_num_args() > 0) {
68 $args = func_get_args();
69 $match = implode(",", array_map('gettype', $args));
70
71 switch($match) {
72 //Rectangular matrix - m x n initialized from 2D array
73 case 'array':
74 $this->m = count($args[0]);
75 $this->n = count($args[0][0]);
76 $this->A = $args[0];
77 break;
78 //Square matrix - n x n
79 case 'integer':
80 $this->m = $args[0];
81 $this->n = $args[0];
82 $this->A = array_fill(0, $this->m, array_fill(0, $this->n, 0));
83 break;
84 //Rectangular matrix - m x n
85 case 'integer,integer':
86 $this->m = $args[0];
87 $this->n = $args[1];
88 $this->A = array_fill(0, $this->m, array_fill(0, $this->n, 0));
89 break;
90 //Rectangular matrix - m x n initialized from packed array
91 case 'array,integer':
92 $this->m = $args[1];
93 if ($this->m != 0) {
94 $this->n = count($args[0]) / $this->m;
95 } else {
96 $this->n = 0;
97 }
98 if (($this->m * $this->n) == count($args[0])) {
99 for($i = 0; $i < $this->m; ++$i) {
100 for($j = 0; $j < $this->n; ++$j) {
101 $this->A[$i][$j] = $args[0][$i + $j * $this->m];
102 }
103 }
104 } else {
106 }
107 break;
108 default:
110 break;
111 }
112 } else {
114 }
115 } // function __construct()
116
117
123 public function getArray() {
124 return $this->A;
125 } // function getArray()
126
127
133 public function getRowDimension() {
134 return $this->m;
135 } // function getRowDimension()
136
137
143 public function getColumnDimension() {
144 return $this->n;
145 } // function getColumnDimension()
146
147
156 public function get($i = null, $j = null) {
157 return $this->A[$i][$j];
158 } // function get()
159
160
171 public function getMatrix() {
172 if (func_num_args() > 0) {
173 $args = func_get_args();
174 $match = implode(",", array_map('gettype', $args));
175
176 switch($match) {
177 //A($i0...; $j0...)
178 case 'integer,integer':
179 list($i0, $j0) = $args;
180 if ($i0 >= 0) { $m = $this->m - $i0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
181 if ($j0 >= 0) { $n = $this->n - $j0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
183 for($i = $i0; $i < $this->m; ++$i) {
184 for($j = $j0; $j < $this->n; ++$j) {
185 $R->set($i, $j, $this->A[$i][$j]);
186 }
187 }
188 return $R;
189 break;
190 //A($i0...$iF; $j0...$jF)
191 case 'integer,integer,integer,integer':
192 list($i0, $iF, $j0, $jF) = $args;
193 if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
194 if (($jF > $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
195 $R = new PHPExcel_Shared_JAMA_Matrix($m+1, $n+1);
196 for($i = $i0; $i <= $iF; ++$i) {
197 for($j = $j0; $j <= $jF; ++$j) {
198 $R->set($i - $i0, $j - $j0, $this->A[$i][$j]);
199 }
200 }
201 return $R;
202 break;
203 //$R = array of row indices; $C = array of column indices
204 case 'array,array':
205 list($RL, $CL) = $args;
206 if (count($RL) > 0) { $m = count($RL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
207 if (count($CL) > 0) { $n = count($CL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
209 for($i = 0; $i < $m; ++$i) {
210 for($j = 0; $j < $n; ++$j) {
211 $R->set($i - $i0, $j - $j0, $this->A[$RL[$i]][$CL[$j]]);
212 }
213 }
214 return $R;
215 break;
216 //$RL = array of row indices; $CL = array of column indices
217 case 'array,array':
218 list($RL, $CL) = $args;
219 if (count($RL) > 0) { $m = count($RL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
220 if (count($CL) > 0) { $n = count($CL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
222 for($i = 0; $i < $m; ++$i) {
223 for($j = 0; $j < $n; ++$j) {
224 $R->set($i, $j, $this->A[$RL[$i]][$CL[$j]]);
225 }
226 }
227 return $R;
228 break;
229 //A($i0...$iF); $CL = array of column indices
230 case 'integer,integer,array':
231 list($i0, $iF, $CL) = $args;
232 if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
233 if (count($CL) > 0) { $n = count($CL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
235 for($i = $i0; $i < $iF; ++$i) {
236 for($j = 0; $j < $n; ++$j) {
237 $R->set($i - $i0, $j, $this->A[$RL[$i]][$j]);
238 }
239 }
240 return $R;
241 break;
242 //$RL = array of row indices
243 case 'array,integer,integer':
244 list($RL, $j0, $jF) = $args;
245 if (count($RL) > 0) { $m = count($RL); } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
246 if (($jF >= $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentBoundsException); }
247 $R = new PHPExcel_Shared_JAMA_Matrix($m, $n+1);
248 for($i = 0; $i < $m; ++$i) {
249 for($j = $j0; $j <= $jF; ++$j) {
250 $R->set($i, $j - $j0, $this->A[$RL[$i]][$j]);
251 }
252 }
253 return $R;
254 break;
255 default:
257 break;
258 }
259 } else {
261 }
262 } // function getMatrix()
263
264
272 public function checkMatrixDimensions($B = null) {
273 if ($B instanceof PHPExcel_Shared_JAMA_Matrix) {
274 if (($this->m == $B->getRowDimension()) && ($this->n == $B->getColumnDimension())) {
275 return true;
276 } else {
278 }
279 } else {
281 }
282 } // function checkMatrixDimensions()
283
284
285
295 public function set($i = null, $j = null, $c = null) {
296 // Optimized set version just has this
297 $this->A[$i][$j] = $c;
298 } // function set()
299
300
309 public function identity($m = null, $n = null) {
310 return $this->diagonal($m, $n, 1);
311 } // function identity()
312
313
323 public function diagonal($m = null, $n = null, $c = 1) {
325 for($i = 0; $i < $m; ++$i) {
326 $R->set($i, $i, $c);
327 }
328 return $R;
329 } // function diagonal()
330
331
340 public function getMatrixByRow($i0 = null, $iF = null) {
341 if (is_int($i0)) {
342 if (is_int($iF)) {
343 return $this->getMatrix($i0, 0, $iF + 1, $this->n);
344 } else {
345 return $this->getMatrix($i0, 0, $i0 + 1, $this->n);
346 }
347 } else {
349 }
350 } // function getMatrixByRow()
351
352
361 public function getMatrixByCol($j0 = null, $jF = null) {
362 if (is_int($j0)) {
363 if (is_int($jF)) {
364 return $this->getMatrix(0, $j0, $this->m, $jF + 1);
365 } else {
366 return $this->getMatrix(0, $j0, $this->m, $j0 + 1);
367 }
368 } else {
370 }
371 } // function getMatrixByCol()
372
373
380 public function transpose() {
381 $R = new PHPExcel_Shared_JAMA_Matrix($this->n, $this->m);
382 for($i = 0; $i < $this->m; ++$i) {
383 for($j = 0; $j < $this->n; ++$j) {
384 $R->set($j, $i, $this->A[$i][$j]);
385 }
386 }
387 return $R;
388 } // function transpose()
389
390
397 public function trace() {
398 $s = 0;
399 $n = min($this->m, $this->n);
400 for($i = 0; $i < $n; ++$i) {
401 $s += $this->A[$i][$i];
402 }
403 return $s;
404 } // function trace()
405
406
413 public function uminus() {
414 } // function uminus()
415
416
424 public function plus() {
425 if (func_num_args() > 0) {
426 $args = func_get_args();
427 $match = implode(",", array_map('gettype', $args));
428
429 switch($match) {
430 case 'object':
431 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
432 break;
433 case 'array':
434 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
435 break;
436 default:
438 break;
439 }
440 $this->checkMatrixDimensions($M);
441 for($i = 0; $i < $this->m; ++$i) {
442 for($j = 0; $j < $this->n; ++$j) {
443 $M->set($i, $j, $M->get($i, $j) + $this->A[$i][$j]);
444 }
445 }
446 return $M;
447 } else {
449 }
450 } // function plus()
451
452
460 public function plusEquals() {
461 if (func_num_args() > 0) {
462 $args = func_get_args();
463 $match = implode(",", array_map('gettype', $args));
464
465 switch($match) {
466 case 'object':
467 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
468 break;
469 case 'array':
470 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
471 break;
472 default:
474 break;
475 }
476 $this->checkMatrixDimensions($M);
477 for($i = 0; $i < $this->m; ++$i) {
478 for($j = 0; $j < $this->n; ++$j) {
479 $validValues = True;
480 $value = $M->get($i, $j);
481 if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
482 $this->A[$i][$j] = trim($this->A[$i][$j],'"');
483 $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
484 }
485 if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
486 $value = trim($value,'"');
488 }
489 if ($validValues) {
490 $this->A[$i][$j] += $value;
491 } else {
492 $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
493 }
494 }
495 }
496 return $this;
497 } else {
499 }
500 } // function plusEquals()
501
502
510 public function minus() {
511 if (func_num_args() > 0) {
512 $args = func_get_args();
513 $match = implode(",", array_map('gettype', $args));
514
515 switch($match) {
516 case 'object':
517 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
518 break;
519 case 'array':
520 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
521 break;
522 default:
524 break;
525 }
526 $this->checkMatrixDimensions($M);
527 for($i = 0; $i < $this->m; ++$i) {
528 for($j = 0; $j < $this->n; ++$j) {
529 $M->set($i, $j, $M->get($i, $j) - $this->A[$i][$j]);
530 }
531 }
532 return $M;
533 } else {
535 }
536 } // function minus()
537
538
546 public function minusEquals() {
547 if (func_num_args() > 0) {
548 $args = func_get_args();
549 $match = implode(",", array_map('gettype', $args));
550
551 switch($match) {
552 case 'object':
553 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
554 break;
555 case 'array':
556 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
557 break;
558 default:
560 break;
561 }
562 $this->checkMatrixDimensions($M);
563 for($i = 0; $i < $this->m; ++$i) {
564 for($j = 0; $j < $this->n; ++$j) {
565 $validValues = True;
566 $value = $M->get($i, $j);
567 if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
568 $this->A[$i][$j] = trim($this->A[$i][$j],'"');
569 $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
570 }
571 if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
572 $value = trim($value,'"');
574 }
575 if ($validValues) {
576 $this->A[$i][$j] -= $value;
577 } else {
578 $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
579 }
580 }
581 }
582 return $this;
583 } else {
585 }
586 } // function minusEquals()
587
588
597 public function arrayTimes() {
598 if (func_num_args() > 0) {
599 $args = func_get_args();
600 $match = implode(",", array_map('gettype', $args));
601
602 switch($match) {
603 case 'object':
604 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
605 break;
606 case 'array':
607 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
608 break;
609 default:
611 break;
612 }
613 $this->checkMatrixDimensions($M);
614 for($i = 0; $i < $this->m; ++$i) {
615 for($j = 0; $j < $this->n; ++$j) {
616 $M->set($i, $j, $M->get($i, $j) * $this->A[$i][$j]);
617 }
618 }
619 return $M;
620 } else {
622 }
623 } // function arrayTimes()
624
625
634 public function arrayTimesEquals() {
635 if (func_num_args() > 0) {
636 $args = func_get_args();
637 $match = implode(",", array_map('gettype', $args));
638
639 switch($match) {
640 case 'object':
641 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
642 break;
643 case 'array':
644 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
645 break;
646 default:
648 break;
649 }
650 $this->checkMatrixDimensions($M);
651 for($i = 0; $i < $this->m; ++$i) {
652 for($j = 0; $j < $this->n; ++$j) {
653 $validValues = True;
654 $value = $M->get($i, $j);
655 if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
656 $this->A[$i][$j] = trim($this->A[$i][$j],'"');
657 $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
658 }
659 if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
660 $value = trim($value,'"');
662 }
663 if ($validValues) {
664 $this->A[$i][$j] *= $value;
665 } else {
666 $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
667 }
668 }
669 }
670 return $this;
671 } else {
673 }
674 } // function arrayTimesEquals()
675
676
685 public function arrayRightDivide() {
686 if (func_num_args() > 0) {
687 $args = func_get_args();
688 $match = implode(",", array_map('gettype', $args));
689
690 switch($match) {
691 case 'object':
692 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
693 break;
694 case 'array':
695 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
696 break;
697 default:
699 break;
700 }
701 $this->checkMatrixDimensions($M);
702 for($i = 0; $i < $this->m; ++$i) {
703 for($j = 0; $j < $this->n; ++$j) {
704 $validValues = True;
705 $value = $M->get($i, $j);
706 if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
707 $this->A[$i][$j] = trim($this->A[$i][$j],'"');
708 $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
709 }
710 if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
711 $value = trim($value,'"');
713 }
714 if ($validValues) {
715 if ($value == 0) {
716 // Trap for Divide by Zero error
717 $M->set($i, $j, '#DIV/0!');
718 } else {
719 $M->set($i, $j, $this->A[$i][$j] / $value);
720 }
721 } else {
723 }
724 }
725 }
726 return $M;
727 } else {
729 }
730 } // function arrayRightDivide()
731
732
741 public function arrayRightDivideEquals() {
742 if (func_num_args() > 0) {
743 $args = func_get_args();
744 $match = implode(",", array_map('gettype', $args));
745
746 switch($match) {
747 case 'object':
748 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
749 break;
750 case 'array':
751 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
752 break;
753 default:
755 break;
756 }
757 $this->checkMatrixDimensions($M);
758 for($i = 0; $i < $this->m; ++$i) {
759 for($j = 0; $j < $this->n; ++$j) {
760 $this->A[$i][$j] = $this->A[$i][$j] / $M->get($i, $j);
761 }
762 }
763 return $M;
764 } else {
766 }
767 } // function arrayRightDivideEquals()
768
769
778 public function arrayLeftDivide() {
779 if (func_num_args() > 0) {
780 $args = func_get_args();
781 $match = implode(",", array_map('gettype', $args));
782
783 switch($match) {
784 case 'object':
785 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
786 break;
787 case 'array':
788 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
789 break;
790 default:
792 break;
793 }
794 $this->checkMatrixDimensions($M);
795 for($i = 0; $i < $this->m; ++$i) {
796 for($j = 0; $j < $this->n; ++$j) {
797 $M->set($i, $j, $M->get($i, $j) / $this->A[$i][$j]);
798 }
799 }
800 return $M;
801 } else {
803 }
804 } // function arrayLeftDivide()
805
806
815 public function arrayLeftDivideEquals() {
816 if (func_num_args() > 0) {
817 $args = func_get_args();
818 $match = implode(",", array_map('gettype', $args));
819
820 switch($match) {
821 case 'object':
822 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
823 break;
824 case 'array':
825 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
826 break;
827 default:
829 break;
830 }
831 $this->checkMatrixDimensions($M);
832 for($i = 0; $i < $this->m; ++$i) {
833 for($j = 0; $j < $this->n; ++$j) {
834 $this->A[$i][$j] = $M->get($i, $j) / $this->A[$i][$j];
835 }
836 }
837 return $M;
838 } else {
840 }
841 } // function arrayLeftDivideEquals()
842
843
851 public function times() {
852 if (func_num_args() > 0) {
853 $args = func_get_args();
854 $match = implode(",", array_map('gettype', $args));
855
856 switch($match) {
857 case 'object':
858 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $B = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
859 if ($this->n == $B->m) {
860 $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
861 for($j = 0; $j < $B->n; ++$j) {
862 for ($k = 0; $k < $this->n; ++$k) {
863 $Bcolj[$k] = $B->A[$k][$j];
864 }
865 for($i = 0; $i < $this->m; ++$i) {
866 $Arowi = $this->A[$i];
867 $s = 0;
868 for($k = 0; $k < $this->n; ++$k) {
869 $s += $Arowi[$k] * $Bcolj[$k];
870 }
871 $C->A[$i][$j] = $s;
872 }
873 }
874 return $C;
875 } else {
876 throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionMismatch));
877 }
878 break;
879 case 'array':
880 $B = new PHPExcel_Shared_JAMA_Matrix($args[0]);
881 if ($this->n == $B->m) {
882 $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
883 for($i = 0; $i < $C->m; ++$i) {
884 for($j = 0; $j < $C->n; ++$j) {
885 $s = "0";
886 for($k = 0; $k < $C->n; ++$k) {
887 $s += $this->A[$i][$k] * $B->A[$k][$j];
888 }
889 $C->A[$i][$j] = $s;
890 }
891 }
892 return $C;
893 } else {
894 throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionMismatch));
895 }
896 return $M;
897 break;
898 case 'integer':
899 $C = new PHPExcel_Shared_JAMA_Matrix($this->A);
900 for($i = 0; $i < $C->m; ++$i) {
901 for($j = 0; $j < $C->n; ++$j) {
902 $C->A[$i][$j] *= $args[0];
903 }
904 }
905 return $C;
906 break;
907 case 'double':
908 $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $this->n);
909 for($i = 0; $i < $C->m; ++$i) {
910 for($j = 0; $j < $C->n; ++$j) {
911 $C->A[$i][$j] = $args[0] * $this->A[$i][$j];
912 }
913 }
914 return $C;
915 break;
916 case 'float':
917 $C = new PHPExcel_Shared_JAMA_Matrix($this->A);
918 for($i = 0; $i < $C->m; ++$i) {
919 for($j = 0; $j < $C->n; ++$j) {
920 $C->A[$i][$j] *= $args[0];
921 }
922 }
923 return $C;
924 break;
925 default:
927 break;
928 }
929 } else {
931 }
932 } // function times()
933
934
942 public function power() {
943 if (func_num_args() > 0) {
944 $args = func_get_args();
945 $match = implode(",", array_map('gettype', $args));
946
947 switch($match) {
948 case 'object':
949 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
950 break;
951 case 'array':
952 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
953 break;
954 default:
956 break;
957 }
958 $this->checkMatrixDimensions($M);
959 for($i = 0; $i < $this->m; ++$i) {
960 for($j = 0; $j < $this->n; ++$j) {
961 $validValues = True;
962 $value = $M->get($i, $j);
963 if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
964 $this->A[$i][$j] = trim($this->A[$i][$j],'"');
965 $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
966 }
967 if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) {
968 $value = trim($value,'"');
970 }
971 if ($validValues) {
972 $this->A[$i][$j] = pow($this->A[$i][$j],$value);
973 } else {
974 $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
975 }
976 }
977 }
978 return $this;
979 } else {
981 }
982 } // function power()
983
984
992 public function concat() {
993 if (func_num_args() > 0) {
994 $args = func_get_args();
995 $match = implode(",", array_map('gettype', $args));
996
997 switch($match) {
998 case 'object':
999 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); }
1000 case 'array':
1001 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
1002 break;
1003 default:
1005 break;
1006 }
1007 $this->checkMatrixDimensions($M);
1008 for($i = 0; $i < $this->m; ++$i) {
1009 for($j = 0; $j < $this->n; ++$j) {
1010 $this->A[$i][$j] = trim($this->A[$i][$j],'"').trim($M->get($i, $j),'"');
1011 }
1012 }
1013 return $this;
1014 } else {
1016 }
1017 } // function concat()
1018
1019
1026 public function solve($B) {
1027 if ($this->m == $this->n) {
1028 $LU = new PHPExcel_Shared_JAMA_LUDecomposition($this);
1029 return $LU->solve($B);
1030 } else {
1031 $QR = new PHPExcel_Shared_JAMA_QRDecomposition($this);
1032 return $QR->solve($B);
1033 }
1034 } // function solve()
1035
1036
1042 public function inverse() {
1043 return $this->solve($this->identity($this->m, $this->m));
1044 } // function inverse()
1045
1046
1053 public function det() {
1055 return $L->det();
1056 } // function det()
1057} // class PHPExcel_Shared_JAMA_Matrix
An exception for terminatinating execution or to throw for unit testing.
PHPExcel root directory.
Definition: Matrix.php:27
inverse()
Matrix inverse or pseudoinverse.
Definition: Matrix.php:1042
getMatrixByRow($i0=null, $iF=null)
getMatrixByRow
Definition: Matrix.php:340
getRowDimension()
getRowDimension
Definition: Matrix.php:133
identity($m=null, $n=null)
identity
Definition: Matrix.php:309
diagonal($m=null, $n=null, $c=1)
diagonal
Definition: Matrix.php:323
arrayLeftDivide()
arrayLeftDivide
Definition: Matrix.php:778
arrayRightDivide()
arrayRightDivide
Definition: Matrix.php:685
solve($B)
Solve A*X = B.
Definition: Matrix.php:1026
getColumnDimension()
getColumnDimension
Definition: Matrix.php:143
arrayTimesEquals()
arrayTimesEquals
Definition: Matrix.php:634
arrayLeftDivideEquals()
arrayLeftDivideEquals
Definition: Matrix.php:815
const PolymorphicArgumentException
Definition: Matrix.php:30
__construct()
Polymorphic constructor.
Definition: Matrix.php:66
arrayRightDivideEquals()
arrayRightDivideEquals
Definition: Matrix.php:741
checkMatrixDimensions($B=null)
checkMatrixDimensions
Definition: Matrix.php:272
getMatrixByCol($j0=null, $jF=null)
getMatrixByCol
Definition: Matrix.php:361
minusEquals()
minusEquals
Definition: Matrix.php:546
static convertToNumberIfFraction(&$operand)
Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is.
Definition: String.php:671
$i
Definition: disco.tpl.php:19
const MatrixDimensionException
Definition: Error.php:39
const PolymorphicArgumentException
Definition: Error.php:24
const ArrayLengthException
Definition: Error.php:60
const ArgumentTypeException
Definition: Error.php:29
const ArgumentBoundsException
Definition: Error.php:34
JAMAError($errorNumber=null)
Custom error handler.
Definition: Error.php:70
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$s
Definition: pwgen.php:45