PHP code example of vermotr / php-matrix

1. Go to this page and download the library: Download vermotr/php-matrix library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vermotr / php-matrix example snippets


use vermotr\Math\Matrix;

// Create a Matrix with its size
$matrix = new Matrix(4, 2);

// With a bi-dimensional array
$matrix = new Matrix([
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8]
]);

// With another Matrix
$matrix = new Matrix($anotherMatrix);

$matrix->getRows();
$matrix->getCols();

$addedScalar = $matrix->add(4);
$addedMatrix = $matrix->add($anotherMatrix);
$subtractedScalar = $matrix->subtract(2);
$subtractedMatrix = $matrix->subtract($anotherMatrix);
$multipliedByScalar = $matrix->multiply(2);
$multipliedByMatrix = $matrix->multiply($anotherMatrix);

if ($matrix1->equals($matrix2)) {
    // Do something!
}

$matrix->adjugate();
$matrix->cofactor();
$matrix->determinant();
$matrix->inverse();
$matrix->subMatrix();
$matrix->transpose();

composer 

"vermotr/php-matrix": "0.1.0"

$matrix[4][2] = 42;

echo $matrix;