src/LinearAlgebra/MatrixFactory.php
private static function createFromVectors(array $A): Matrix
    {
        // Check that all vectors are the same length
        $m = $A[0]->getN();
        $n = count($A);
        for ($j = 1; $j < $n; $j++) {
            if ($A[$j]->getN() !== $m) {
                throw new Exception\MatrixException('Vectors being combined into matrix have different lengths');
            }
        }

        // Concatenate all the vectors
        $R = [];
        foreach ($A as $V) {
            $R[] = $V->getVector();
        }

        // Transpose to create matrix from the vector columns
        return (new Matrix($R))->transpose();
    }
private static function createFromVectors(array $A): Matrix
    {
        // Check that all vectors are the same length
        $m = $A[0]->getN();
        $n = count($A);
        for ($j = 1; $j < $n; $j++) {
            if ($A[$j]->getN() !== $m) {
                throw new Exception\MatrixException('Vectors being combined into matrix have different lengths');
            }
        }

        // Concatenate all the vectors
        $R = [];
        foreach ($A as $V) {
            $R[] = $V->getVector();
        }

        // Transpose to create matrix from the vector columns
        return (new Matrix($R))->transpose();
    }
private static function createFromVectors ( array $ A ) : Matrix { // Check that all vectors are the same length $ m = $ A [ 0 ] -> getN ( ) ; $ n = count ( $ A ) ; for ( $ j = 1 ; $ j < $ n ; $ j ++ ) { if ( $ A [ $ j ] -> getN ( ) !== $ m ) { throw new Exception \ MatrixException ( 'Vectors being combined into matrix have different lengths' ) ; } } // Concatenate all the vectors $ R = [ ] ; foreach ( $ A as $ V ) { $ R [ ] = $ V -> getVector ( ) ; } // Transpose to create matrix from the vector columns return ( new Matrix ( $ R ) ) -> transpose ( ) ; }
Create a matrix from an array of Vectors

Example:
[1]       [4]        [7]       [8]
X₁ = [2]  X₂ = [2]   X₃ = [8]  X₄ = [4]
[1]       [13]       [1]       [5]

[1  4 7 8]
R = [2  2 8 4]
[1 13 1 5]

@param  array $A array of Vectors

@return Matrix

@throws Exception\MatrixException if the Vectors are not all the same length
@throws Exception\IncorrectTypeException
@throws Exception\BadDataException
Create a matrix from an array of Vectors