PHP Class MathPHP\LinearAlgebra\MatrixFactory

Use factory instead of instantiating individual Matrix classes.
ファイルを表示 Open project: markrogoyski/math-php Class Usage Examples

Public Methods

Method Description
create ( array $A, integer $n = null ) : Matrix Factory method
eye ( integer $m, integer $n, integer $k, number $x = 1 ) : Matrix Eye matrix - ones on the k diagonal and zeros everywhere else.
identity ( integer $n, number $x = 1 ) : SquareMatrix Identity matrix - n x n matrix with ones in the diagonal Option to set the diagonal to any number.
one ( integer $m, integer $n ) : Matrix Ones matrix - m x n matrix with all elements being ones
zero ( integer $m, integer $n ) : Matrix Zero matrix - m x n matrix with all elements being zeros

Private Methods

Method Description
checkParams ( array $A, integer $n = null ) : boolean Check input parameters
determineMatrixType ( array $A, $vandermonde_n ) : string Determine what type of matrix to create

Method Details

create() public static method

Factory method
public static create ( array $A, integer $n = null ) : Matrix
$A array 1- or 2-dimensional array of Matrix data 1-dimensional array for Diagonal and Vandermonde matrices 2-dimensional array for Square, Function, and regular Matrices
$n integer Optional n for Vandermonde matrix
return Matrix

eye() public static method

Diagonal can start at any column. Option to set the diagonal to any number. Example: m = 3; n = 3; k = 1; x = 1 (3x3 matrix with 1s on the kth (1) diagonal) [0 1 0] A = [0 0 1] [0 0 0]
public static eye ( integer $m, integer $n, integer $k, number $x = 1 ) : Matrix
$m integer number of rows
$n integer number of columns
$k integer Diagonal to fill with xs
$x number (optional; default 1)
return Matrix

identity() public static method

Example: n = 3; x = 1 [1 0 0] A = [0 1 0] [0 0 1]
public static identity ( integer $n, number $x = 1 ) : SquareMatrix
$n integer size of matrix
$x number (optional; default 1)
return SquareMatrix

one() public static method

Example: m = 3; n = 3 [1 1 1] A = [1 1 1] [1 1 1]
public static one ( integer $m, integer $n ) : Matrix
$m integer rows
$n integer columns
return Matrix

zero() public static method

Example: m = 3; n = 3 [0 0 0] A = [0 0 0] [0 0 0]
public static zero ( integer $m, integer $n ) : Matrix
$m integer rows
$n integer columns
return Matrix