PHP Classes
elePHPant
Icontem

Morpheus: Perform calculations with matrices

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-06-25 (5 months ago) RSS 2.0 feedNot enough user ratingsTotal: 74 All time: 8,953 This week: 551Up
Version License PHP version Categories
morpheus 1.0.0Custom (specified...5PHP 5, Math
Description Author

This class can perform calculations with matrices.

It may take as parameter a bi-dimensional array with the values of a matrix cells.

The class can perform several operations with the matrix, like adding and subtracting matrix values, multiplying or dividing by a scalar value, multiplying matrices by each other, transposing, etc..

  Performance   Level  
Name: Julian Finkler <contact>
Classes: 6 packages by
Country: Germany Germany
Age: 24
All time rank: 3647202 in Germany Germany
Week rank: 64 Up3 in Germany Germany Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Details

GitHub tag License Travis Packagist

Morpheus

Morpheus is a matrix calculation class for PHP

Installation

$ composer require devtronic/morpheus

Usage

Create a Matrix

<?php

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]
]);

Simple Operations

Add

<?php

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] ]

Subtract

<?php

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] ]

Multiply

<?php

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],
// ]

Scalar Operations

Scalar Multiply

<?php

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],
// ]

Scalar Division

<?php

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],
// ]

Custom Operations

Scalar Operations

<?php

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],
// ]

"Synchronous" Operations

<?php

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],
// ]

Transformation

Transpose

<?php

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],
// ]
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (2 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Matrix.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file autoload.php Aux. Auxiliary script
  Plain text file MatrixTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:74
This week:0
All time:8,953
This week:551Up