MathPHP\LinearAlgebra\MatrixFactory::create PHP Method

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
    public static function create(array $A, int $n = null) : Matrix
    {
        self::checkParams($A, $n);
        $matrix_type = self::determineMatrixType($A, $n);
        switch ($matrix_type) {
            case 'matrix':
                return new Matrix($A);
            case 'square':
                return new SquareMatrix($A);
            case 'diagonal':
                return new DiagonalMatrix($A);
            case 'vandermonde':
                return new VandermondeMatrix($A, $n);
            case 'function':
                return new FunctionMatrix($A);
            case 'vandermonde_square':
                return new VandermondeSquareMatrix($A, $n);
            case 'function_square':
                return new FunctionSquareMatrix($A);
        }
        throw new Exception\IncorrectTypeException('Unknown matrix type');
    }

Usage Example

 public function evaluate(array $params)
 {
     $m = $this->m;
     $n = $this->n;
     $R = [];
     for ($i = 0; $i < $m; $i++) {
         for ($j = 0; $j < $n; $j++) {
             $func = $this->A[$i][$j];
             $R[$i][$j] = $func($params);
         }
     }
     return MatrixFactory::create($R);
 }
All Usage Examples Of MathPHP\LinearAlgebra\MatrixFactory::create