PHP code example of busybrain / matrix

1. Go to this page and download the library: Download busybrain/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/ */

    

busybrain / matrix example snippets




$matrix  = Matrix::make([
	[1,2,3],
	[5,6,7]
	]);



$matrix->set([
	[1,2,3],
	[5,6,7]
	])->setScalar(2);



$matrix->identity($row,$col);


$matrix->scalarToMatrix($value,$row,$col);




$matrix->first() : array //returns the first matrix on the matrix instance 

$matrix->howManyMatrix():int  //returns the number of matrix set on the matrix instance 

$matrix->rowCount() : int //returns the number of rows present on the array

$matrix->columnCount() : int //returns the number of column present on the array

$matrix->pickRow(int $row):array //returns the selcted row

$matrix->pickColumn($col) : array //returns the selected column

$matrix->lu() : array //returns a multidimensional array of the lower and upper triangular matrix

$matrix->rowDel($row) : array // returns a new matrix with the given row deleted

$matrix->colDel($col) : array //returns a new matrix with the given column deleted

$matrix->dimensions() : array //returns an array of [row,column]

}


 

$matrix = Matrix::make([[1,2,3],[4,5,6]]);

$matrix->validate(['square','singular','dim:2,3']);



$matrix->validate([functiion($matrix,$fail){
		if($matrix->rowCount() < 1){
			return $fail('matrix row count less than 1');
		}
		return true;
	}]);



$matrix->validateWithMessage(['square','dim:2,3',functiion($matrix,$fail){
		if($matrix->rowCount() < 1){
			return $fail('matrix row count less than 1');
		}
		return true;
	}]);