PHP code example of devtronic / morpheus

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

    

devtronic / morpheus example snippets




use Devtronic\Morpheus\Matrix;

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

// or

$matrix = new Matrix();
$matrix->setData([
    [1, 2, 3],
    [4, 5, 6]
]);



use Devtronic\Morpheus\Matrix;

$matrixA = new Matrix([
    [1, 2, 3],
]);

$matrixB = new Matrix([
    [4, 5, 6],
]);

$matrixA->add($matrixB);

print_r($matrixA->getData());
// [ [5, 7, 9] ]



use Devtronic\Morpheus\Matrix;

$matrixA = new Matrix([
    [4, 5, 6],
]);

$matrixB = new Matrix([
    [1, 2, 3],
]);

$matrixA->subtract($matrixB);

print_r($matrixA->getData());
// [ [3, 3, 3] ]



use Devtronic\Morpheus\Matrix;

$matrixA = new Matrix([
    [1, 2, 3],
    [3, 2, 1],
]);

$matrixB = new Matrix([
    [1, 2],
    [10, 20],
    [100, 200],
]);

$matrixA->subtract($matrixB);

print_r($matrixA->getData());
// [
//     [321, 642],
//     [123, 246],
// ]



use Devtronic\Morpheus\Matrix;

$matrix = new Matrix([
    [1, 2, 3],
    [3, 2, 1],
]);

$matrix->scalarMultiply(5);

print_r($matrix->getData());
// [
//     [5, 10, 15],
//     [15, 10, 5],
// ]



use Devtronic\Morpheus\Matrix;

$matrix = new Matrix([
    [10, 15, 30],
    [30, 10, 15],
]);

$matrix->scalarDivide(5);

print_r($matrix->getData());
// [
//     [2, 3, 10],
//     [10, 2, 3],
// ]



use Devtronic\Morpheus\Matrix;

$matrix = new Matrix([
    [1, 0, 0],
    [1, 1, 0],
]);

$matrix->scalarMatrixOperation(function($element) {
    return $element == 1 ? 0 : 1;
});

print_r($matrix->getData());
// [
//     [0, 1, 1],
//     [0, 0, 1],
// ]



use Devtronic\Morpheus\Matrix;

$matrixA = new Matrix([
    [1, 0, 0],
    [1, 1, 0],
]);

$matrixB = new Matrix([
    [1, 1, 0],
    [0, 1, 0],
]);

// Simple XOR Operation
$matrixA->synchronousMatrixOperation($matrixB, function($left, $right) {
    return intval($left ^ $right);
});

print_r($matrixA->getData());
// [
//     [0, 1, 0],
//     [1, 0, 0],
// ]



use Devtronic\Morpheus\Matrix;

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

$matrix->transpose();

print_r($matrixA->getData());
// [
//     [1, 3, 5],
//     [2, 4, 6],
// ]