ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
PHPExcel_Shared_JAMA_Matrix Class Reference

PHPExcel root directory. More...

+ Collaboration diagram for PHPExcel_Shared_JAMA_Matrix:

Public Member Functions

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

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

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.

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

{
if (func_num_args() > 0) {
$args = func_get_args();
$match = implode(",", array_map('gettype', $args));
switch($match) {
//Rectangular matrix - m x n initialized from 2D array
case 'array':
$this->m = count($args[0]);
$this->n = count($args[0][0]);
$this->A = $args[0];
break;
//Square matrix - n x n
case 'integer':
$this->m = $args[0];
$this->n = $args[0];
$this->A = array_fill(0, $this->m, array_fill(0, $this->n, 0));
break;
//Rectangular matrix - m x n
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;
//Rectangular matrix - m x n initialized from packed array
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 {
}
break;
default:
break;
}
} else {
}
} // function __construct()

Member Function Documentation

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.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function arrayLeftDivide()

+ Here is the call graph for this function:

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.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function arrayLeftDivideEquals()

+ Here is the call graph for this function:

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.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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,'"');
}
if ($validValues) {
if ($value == 0) {
// Trap for Divide by Zero error
$M->set($i, $j, '#DIV/0!');
} else {
$M->set($i, $j, $this->A[$i][$j] / $value);
}
} else {
}
}
}
return $M;
} else {
}
} // function arrayRightDivide()

+ Here is the call graph for this function:

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.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function arrayRightDivideEquals()

+ Here is the call graph for this function:

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.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function arrayTimes()

+ Here is the call graph for this function:

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.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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,'"');
}
if ($validValues) {
$this->A[$i][$j] *= $value;
} else {
}
}
}
return $this;
} else {
}
} // function arrayTimesEquals()

+ Here is the call graph for this function:

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.

References ArgumentTypeException, MatrixDimensionException, and n.

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

{
if ($B instanceof PHPExcel_Shared_JAMA_Matrix) {
if (($this->m == $B->getRowDimension()) && ($this->n == $B->getColumnDimension())) {
return true;
} else {
}
} else {
}
} // function checkMatrixDimensions()

+ Here is the caller graph for this function:

PHPExcel_Shared_JAMA_Matrix::concat ( )

concat

A = A & B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 992 of file Matrix.php.

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

{
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 Exception(self::ArgumentTypeException); }
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function concat()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::det ( )

det

Calculate determinant

Returns
float Determinant

Definition at line 1053 of file Matrix.php.

{
return $L->det();
} // function det()
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.

References $m, and $n.

Referenced by identity().

{
for($i = 0; $i < $m; ++$i) {
$R->set($i, $i, $c);
}
return $R;
} // function diagonal()

+ Here is the caller graph for this function:

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.

{
return $this->A[$i][$j];
} // function get()
PHPExcel_Shared_JAMA_Matrix::getArray ( )

getArray

Returns
array Matrix array

Definition at line 123 of file Matrix.php.

References $A.

{
return $this->A;
} // function getArray()
PHPExcel_Shared_JAMA_Matrix::getColumnDimension ( )

getColumnDimension

Returns
int Column dimension

Definition at line 143 of file Matrix.php.

References $n.

{
return $this->n;
} // function getColumnDimension()
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.

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

Referenced by getMatrixByCol(), and getMatrixByRow().

{
if (func_num_args() > 0) {
$args = func_get_args();
$match = implode(",", array_map('gettype', $args));
switch($match) {
//A($i0...; $j0...)
case 'integer,integer':
list($i0, $j0) = $args;
if ($i0 >= 0) { $m = $this->m - $i0; } else { throw new Exception(self::ArgumentBoundsException); }
if ($j0 >= 0) { $n = $this->n - $j0; } else { throw new Exception(self::ArgumentBoundsException); }
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;
//A($i0...$iF; $j0...$jF)
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 Exception(self::ArgumentBoundsException); }
if (($jF > $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { throw new Exception(self::ArgumentBoundsException); }
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;
//$R = array of row indices; $C = array of column indices
case 'array,array':
list($RL, $CL) = $args;
if (count($RL) > 0) { $m = count($RL); } else { throw new Exception(self::ArgumentBoundsException); }
if (count($CL) > 0) { $n = count($CL); } else { throw new Exception(self::ArgumentBoundsException); }
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;
//$RL = array of row indices; $CL = array of column indices
case 'array,array':
list($RL, $CL) = $args;
if (count($RL) > 0) { $m = count($RL); } else { throw new Exception(self::ArgumentBoundsException); }
if (count($CL) > 0) { $n = count($CL); } else { throw new 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;
//A($i0...$iF); $CL = array of column indices
case 'integer,integer,array':
list($i0, $iF, $CL) = $args;
if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { throw new Exception(self::ArgumentBoundsException); }
if (count($CL) > 0) { $n = count($CL); } else { throw new 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;
//$RL = array of row indices
case 'array,integer,integer':
list($RL, $j0, $jF) = $args;
if (count($RL) > 0) { $m = count($RL); } else { throw new Exception(self::ArgumentBoundsException); }
if (($jF >= $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { throw new 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:
break;
}
} else {
}
} // function getMatrix()

+ Here is the caller graph for this function:

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.

References ArgumentTypeException, and getMatrix().

{
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 {
}
} // function getMatrixByCol()

+ Here is the call graph for this function:

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.

References ArgumentTypeException, getMatrix(), and n.

{
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 {
}
} // function getMatrixByRow()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::getRowDimension ( )

getRowDimension

Returns
int Row dimension

Definition at line 133 of file Matrix.php.

References $m.

{
return $this->m;
} // function getRowDimension()
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.

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

Referenced by inverse().

{
return $this->diagonal($m, $n, 1);
} // function identity()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References identity(), and solve().

{
return $this->solve($this->identity($this->m, $this->m));
} // function inverse()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::minus ( )

minus

A - B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 510 of file Matrix.php.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function minus()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::minusEquals ( )

minusEquals

A = A - B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 546 of file Matrix.php.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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,'"');
}
if ($validValues) {
$this->A[$i][$j] -= $value;
} else {
}
}
}
return $this;
} else {
}
} // function minusEquals()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::plus ( )

plus

A + B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 424 of file Matrix.php.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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 {
}
} // function plus()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::plusEquals ( )

plusEquals

A = A + B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 460 of file Matrix.php.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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,'"');
}
if ($validValues) {
$this->A[$i][$j] += $value;
} else {
}
}
}
return $this;
} else {
}
} // function plusEquals()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::power ( )

power

A = A ^ B

Parameters
mixed$BMatrix/Array
Returns
Matrix Sum

Definition at line 942 of file Matrix.php.

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

{
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 Exception(self::ArgumentTypeException); }
break;
case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break;
default:
break;
}
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,'"');
}
if ($validValues) {
$this->A[$i][$j] = pow($this->A[$i][$j],$value);
} else {
}
}
}
return $this;
} else {
}
} // function power()

+ Here is the call graph for this function:

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.

{
// Optimized set version just has this
$this->A[$i][$j] = $c;
} // function set()
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.

References n.

Referenced by inverse().

{
if ($this->m == $this->n) {
return $LU->solve($B);
} else {
$QR = new QRDecomposition($this);
return $QR->solve($B);
}
} // function solve()

+ Here is the caller graph for this function:

PHPExcel_Shared_JAMA_Matrix::times ( )

times

Matrix multiplication

Parameters
mixed$nMatrix/Array/Scalar
Returns
Matrix Product

Definition at line 851 of file Matrix.php.

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

{
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 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 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 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:
break;
}
} else {
}
} // function times()

+ Here is the call graph for this function:

PHPExcel_Shared_JAMA_Matrix::trace ( )

trace

Sum of diagonal elements

Returns
float Sum of diagonal elements

Definition at line 397 of file Matrix.php.

References $n, and n.

{
$s = 0;
$n = min($this->m, $this->n);
for($i = 0; $i < $n; ++$i) {
$s += $this->A[$i][$i];
}
return $s;
} // function trace()
PHPExcel_Shared_JAMA_Matrix::transpose ( )

transpose

Tranpose matrix

Returns
Matrix Transposed matrix

Definition at line 380 of file Matrix.php.

References $m, $n, and n.

{
$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;
} // function transpose()
PHPExcel_Shared_JAMA_Matrix::uminus ( )

uminus

Unary minus matrix -A

Returns
Matrix Unary minus matrix

Definition at line 413 of file Matrix.php.

{
} // function uminus()

Field Documentation

PHPExcel_Shared_JAMA_Matrix::$A = array()

Definition at line 42 of file Matrix.php.

Referenced by getArray().

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

Definition at line 32 of file Matrix.php.

const PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException = "Invalid argument type."
const PHPExcel_Shared_JAMA_Matrix::ArrayLengthException = "Array length must be a multiple of m."

Definition at line 34 of file Matrix.php.

const PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException = "Matrix dimensions are not equal."
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: