ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
PHPExcel_Shared_JAMA_Matrix Class Reference

PHPExcel root directory. More...

+ Collaboration diagram for PHPExcel_Shared_JAMA_Matrix:

Public Member Functions

 __construct ()
 Polymorphic constructor. More...
 
 getArray ()
 getArray More...
 
 getRowDimension ()
 getRowDimension More...
 
 getColumnDimension ()
 getColumnDimension More...
 
 get ($i=null, $j=null)
 get More...
 
 getMatrix ()
 getMatrix More...
 
 checkMatrixDimensions ($B=null)
 checkMatrixDimensions More...
 
 set ($i=null, $j=null, $c=null)
 set More...
 
 identity ($m=null, $n=null)
 identity More...
 
 diagonal ($m=null, $n=null, $c=1)
 diagonal More...
 
 getMatrixByRow ($i0=null, $iF=null)
 getMatrixByRow More...
 
 getMatrixByCol ($j0=null, $jF=null)
 getMatrixByCol More...
 
 transpose ()
 transpose More...
 
 trace ()
 trace More...
 
 uminus ()
 uminus More...
 
 plus ()
 plus More...
 
 plusEquals ()
 plusEquals More...
 
 minus ()
 minus More...
 
 minusEquals ()
 minusEquals More...
 
 arrayTimes ()
 arrayTimes More...
 
 arrayTimesEquals ()
 arrayTimesEquals More...
 
 arrayRightDivide ()
 arrayRightDivide More...
 
 arrayRightDivideEquals ()
 arrayRightDivideEquals More...
 
 arrayLeftDivide ()
 arrayLeftDivide More...
 
 arrayLeftDivideEquals ()
 arrayLeftDivideEquals More...
 
 times ()
 times More...
 
 power ()
 power More...
 
 concat ()
 concat More...
 
 solve ($B)
 Solve A*X = B. More...
 
 inverse ()
 Matrix inverse or pseudoinverse. More...
 
 det ()
 det More...
 

Data Fields

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."
 
 $A = array()
 

Private Attributes

 $m
 
 $n
 

Detailed Description

PHPExcel root directory.

Definition at line 27 of file Matrix.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_Shared_JAMA_Matrix::__construct ( )

Polymorphic constructor.

As PHP has no support for polymorphic constructors, we hack our own sort of polymorphism using func_num_args, func_get_arg, and gettype. In essence, we're just implementing a simple RTTI filter and calling the appropriate constructor.

Definition at line 66 of file Matrix.php.

66 {
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()
const PolymorphicArgumentException
Definition: Error.php:24
const ArrayLengthException
Definition: Error.php:60

References $m, $n, ArrayLengthException, and PolymorphicArgumentException.

Member Function Documentation

◆ arrayLeftDivide()

PHPExcel_Shared_JAMA_Matrix::arrayLeftDivide ( )

arrayLeftDivide

Element-by-element Left division A / B

Parameters
Matrix$BMatrix B
Returns
Matrix Division result

Definition at line 778 of file Matrix.php.

778 {
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()
const ArgumentTypeException
Definition: Error.php:29
PHPExcel root directory.
Definition: Matrix.php:27
checkMatrixDimensions($B=null)
checkMatrixDimensions
Definition: Matrix.php:272

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ arrayLeftDivideEquals()

PHPExcel_Shared_JAMA_Matrix::arrayLeftDivideEquals ( )

arrayLeftDivideEquals

Element-by-element Left division Aij = Aij / Bij

Parameters
mixed$BMatrix/Array
Returns
Matrix Matrix Aij

Definition at line 815 of file Matrix.php.

815 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ arrayRightDivide()

PHPExcel_Shared_JAMA_Matrix::arrayRightDivide ( )

arrayRightDivide

Element-by-element right division A / B

Parameters
Matrix$BMatrix B
Returns
Matrix Division result

Definition at line 685 of file Matrix.php.

685 {
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 {
722 $M->set($i, $j, PHPExcel_Calculation_Functions::NaN());
723 }
724 }
725 }
726 return $M;
727 } else {
729 }
730 } // function arrayRightDivide()
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

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), PHPExcel_Shared_String\convertToNumberIfFraction(), PHPExcel_Calculation_Functions\NaN(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ arrayRightDivideEquals()

PHPExcel_Shared_JAMA_Matrix::arrayRightDivideEquals ( )

arrayRightDivideEquals

Element-by-element right division Aij = Aij / Bij

Parameters
mixed$BMatrix/Array
Returns
Matrix Matrix Aij

Definition at line 741 of file Matrix.php.

741 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ arrayTimes()

PHPExcel_Shared_JAMA_Matrix::arrayTimes ( )

arrayTimes

Element-by-element multiplication Cij = Aij * Bij

Parameters
mixed$BMatrix/Array
Returns
Matrix Matrix Cij

Definition at line 597 of file Matrix.php.

597 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ arrayTimesEquals()

PHPExcel_Shared_JAMA_Matrix::arrayTimesEquals ( )

arrayTimesEquals

Element-by-element multiplication Aij = Aij * Bij

Parameters
mixed$BMatrix/Array
Returns
Matrix Matrix Aij

Definition at line 634 of file Matrix.php.

634 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), PHPExcel_Shared_String\convertToNumberIfFraction(), PHPExcel_Calculation_Functions\NaN(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ checkMatrixDimensions()

PHPExcel_Shared_JAMA_Matrix::checkMatrixDimensions (   $B = null)

checkMatrixDimensions

Is matrix B the same size?

Parameters
Matrix$BMatrix B
Returns
boolean

Definition at line 272 of file Matrix.php.

272 {
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()
const MatrixDimensionException
Definition: Error.php:39

References ArgumentTypeException, and MatrixDimensionException.

Referenced by arrayLeftDivide(), arrayLeftDivideEquals(), arrayRightDivide(), arrayRightDivideEquals(), arrayTimes(), arrayTimesEquals(), concat(), minus(), minusEquals(), plus(), plusEquals(), and power().

+ Here is the caller graph for this function:

◆ concat()

PHPExcel_Shared_JAMA_Matrix::concat ( )

concat

A = A & B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 992 of file Matrix.php.

992 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ det()

PHPExcel_Shared_JAMA_Matrix::det ( )

det

Calculate determinant

Returns
float Determinant

Definition at line 1053 of file Matrix.php.

1053 {
1055 return $L->det();
1056 } // function det()

◆ diagonal()

PHPExcel_Shared_JAMA_Matrix::diagonal (   $m = null,
  $n = null,
  $c = 1 
)

diagonal

Generate a diagonal matrix

Parameters
int$mRow dimension
int$nColumn dimension
mixed$cDiagonal value
Returns
Matrix Diagonal matrix

Definition at line 323 of file Matrix.php.

323 {
325 for($i = 0; $i < $m; ++$i) {
326 $R->set($i, $i, $c);
327 }
328 return $R;
329 } // function diagonal()

References $m, and $n.

Referenced by identity().

+ Here is the caller graph for this function:

◆ get()

PHPExcel_Shared_JAMA_Matrix::get (   $i = null,
  $j = null 
)

get

Get the i,j-th element of the matrix.

Parameters
int$iRow position
int$jColumn position
Returns
mixed Element (int/float/double)

Definition at line 156 of file Matrix.php.

156 {
157 return $this->A[$i][$j];
158 } // function get()

◆ getArray()

PHPExcel_Shared_JAMA_Matrix::getArray ( )

getArray

Returns
array Matrix array

Definition at line 123 of file Matrix.php.

123 {
124 return $this->A;
125 } // function getArray()

References $A.

◆ getColumnDimension()

PHPExcel_Shared_JAMA_Matrix::getColumnDimension ( )

getColumnDimension

Returns
int Column dimension

Definition at line 143 of file Matrix.php.

143 {
144 return $this->n;
145 } // function getColumnDimension()

References $n.

◆ getMatrix()

PHPExcel_Shared_JAMA_Matrix::getMatrix ( )

getMatrix

Get a submatrix

Parameters
int$i0Initial row index
int$iFFinal row index
int$j0Initial column index
int$jFFinal column index
Returns
Matrix Submatrix

Definition at line 171 of file Matrix.php.

171 {
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()
const ArgumentBoundsException
Definition: Error.php:34

References $m, $n, ArgumentBoundsException, and PolymorphicArgumentException.

Referenced by getMatrixByCol(), and getMatrixByRow().

+ Here is the caller graph for this function:

◆ getMatrixByCol()

PHPExcel_Shared_JAMA_Matrix::getMatrixByCol (   $j0 = null,
  $jF = null 
)

getMatrixByCol

Get a submatrix by column index/range

Parameters
int$i0Initial column index
int$iFFinal column index
Returns
Matrix Submatrix

Definition at line 361 of file Matrix.php.

361 {
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()

References ArgumentTypeException, and getMatrix().

+ Here is the call graph for this function:

◆ getMatrixByRow()

PHPExcel_Shared_JAMA_Matrix::getMatrixByRow (   $i0 = null,
  $iF = null 
)

getMatrixByRow

Get a submatrix by row index/range

Parameters
int$i0Initial row index
int$iFFinal row index
Returns
Matrix Submatrix

Definition at line 340 of file Matrix.php.

340 {
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()

References ArgumentTypeException, and getMatrix().

+ Here is the call graph for this function:

◆ getRowDimension()

PHPExcel_Shared_JAMA_Matrix::getRowDimension ( )

getRowDimension

Returns
int Row dimension

Definition at line 133 of file Matrix.php.

133 {
134 return $this->m;
135 } // function getRowDimension()

References $m.

◆ identity()

PHPExcel_Shared_JAMA_Matrix::identity (   $m = null,
  $n = null 
)

identity

Generate an identity matrix.

Parameters
int$mRow dimension
int$nColumn dimension
Returns
Matrix Identity matrix

Definition at line 309 of file Matrix.php.

309 {
310 return $this->diagonal($m, $n, 1);
311 } // function identity()
diagonal($m=null, $n=null, $c=1)
diagonal
Definition: Matrix.php:323

References $m, $n, and diagonal().

Referenced by inverse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inverse()

PHPExcel_Shared_JAMA_Matrix::inverse ( )

Matrix inverse or pseudoinverse.

Returns
Matrix ... Inverse(A) if A is square, pseudoinverse otherwise.

Definition at line 1042 of file Matrix.php.

1042 {
1043 return $this->solve($this->identity($this->m, $this->m));
1044 } // function inverse()
identity($m=null, $n=null)
identity
Definition: Matrix.php:309
solve($B)
Solve A*X = B.
Definition: Matrix.php:1026

References identity(), and solve().

+ Here is the call graph for this function:

◆ minus()

PHPExcel_Shared_JAMA_Matrix::minus ( )

minus

A - B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 510 of file Matrix.php.

510 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ minusEquals()

PHPExcel_Shared_JAMA_Matrix::minusEquals ( )

minusEquals

A = A - B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 546 of file Matrix.php.

546 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), PHPExcel_Shared_String\convertToNumberIfFraction(), PHPExcel_Calculation_Functions\NaN(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ plus()

PHPExcel_Shared_JAMA_Matrix::plus ( )

plus

A + B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 424 of file Matrix.php.

424 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ plusEquals()

PHPExcel_Shared_JAMA_Matrix::plusEquals ( )

plusEquals

A = A + B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 460 of file Matrix.php.

460 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), PHPExcel_Shared_String\convertToNumberIfFraction(), PHPExcel_Calculation_Functions\NaN(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ power()

PHPExcel_Shared_JAMA_Matrix::power ( )

power

A = A ^ B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 942 of file Matrix.php.

942 {
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()

References $m, $n, ArgumentTypeException, checkMatrixDimensions(), PHPExcel_Shared_String\convertToNumberIfFraction(), PHPExcel_Calculation_Functions\NaN(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ set()

PHPExcel_Shared_JAMA_Matrix::set (   $i = null,
  $j = null,
  $c = null 
)

set

Set the i,j-th element of the matrix.

Parameters
int$iRow position
int$jColumn position
mixed$cInt/float/double value
Returns
mixed Element (int/float/double)

Definition at line 295 of file Matrix.php.

295 {
296 // Optimized set version just has this
297 $this->A[$i][$j] = $c;
298 } // function set()

◆ solve()

PHPExcel_Shared_JAMA_Matrix::solve (   $B)

Solve A*X = B.

Parameters
Matrix$BRight hand side
Returns
Matrix ... Solution if A is square, least squares solution otherwise

Definition at line 1026 of file Matrix.php.

1026 {
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()

Referenced by inverse().

+ Here is the caller graph for this function:

◆ times()

PHPExcel_Shared_JAMA_Matrix::times ( )

times

Matrix multiplication

Parameters
mixed$nMatrix/Array/Scalar
Returns
Matrix Product

Definition at line 851 of file Matrix.php.

851 {
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()
JAMAError($errorNumber=null)
Custom error handler.
Definition: Error.php:70

References $m, $n, ArgumentTypeException, JAMAError(), and PolymorphicArgumentException.

+ Here is the call graph for this function:

◆ trace()

PHPExcel_Shared_JAMA_Matrix::trace ( )

trace

Sum of diagonal elements

Returns
float Sum of diagonal elements

Definition at line 397 of file Matrix.php.

397 {
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()

References $n.

◆ transpose()

PHPExcel_Shared_JAMA_Matrix::transpose ( )

transpose

Tranpose matrix

Returns
Matrix Transposed matrix

Definition at line 380 of file Matrix.php.

380 {
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()

References $m, and $n.

◆ uminus()

PHPExcel_Shared_JAMA_Matrix::uminus ( )

uminus

Unary minus matrix -A

Returns
Matrix Unary minus matrix

Definition at line 413 of file Matrix.php.

413 {
414 } // function uminus()

Field Documentation

◆ $A

PHPExcel_Shared_JAMA_Matrix::$A = array()

Definition at line 42 of file Matrix.php.

Referenced by getArray().

◆ $m

◆ $n

◆ ArgumentBoundsException

const PHPExcel_Shared_JAMA_Matrix::ArgumentBoundsException = "Invalid argument range."

Definition at line 32 of file Matrix.php.

◆ ArgumentTypeException

const PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException = "Invalid argument type."

◆ ArrayLengthException

const PHPExcel_Shared_JAMA_Matrix::ArrayLengthException = "Array length must be a multiple of m."

Definition at line 34 of file Matrix.php.

◆ MatrixDimensionException

const PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException = "Matrix dimensions are not equal."

◆ PolymorphicArgumentException

const PHPExcel_Shared_JAMA_Matrix::PolymorphicArgumentException = "Invalid argument pattern for polymorphic function."

Definition at line 30 of file Matrix.php.


The documentation for this class was generated from the following file: