An open API service indexing awesome lists of open source software.

https://github.com/devtronic/morpheus

A PHP matrix calculation helper
https://github.com/devtronic/morpheus

Last synced: 4 months ago
JSON representation

A PHP matrix calculation helper

Awesome Lists containing this project

README

          

[![GitHub tag](https://img.shields.io/packagist/v/devtronic/morpheus.svg)](https://github.com/Devtronic/morpheus)
[![License](https://img.shields.io/packagist/l/Devtronic/morpheus.svg)](https://github.com/Devtronic/morpheus/blob/master/LICENSE)
[![Travis](https://img.shields.io/travis/Devtronic/morpheus.svg)](https://travis-ci.org/Devtronic/morpheus)
[![Packagist](https://img.shields.io/packagist/dt/Devtronic/morpheus.svg)](https://packagist.org/packages/devtronic/morpheus)

# Morpheus
Morpheus is a matrix calculation class for PHP

## Installation
```bash
$ composer require devtronic/morpheus
```

## Usage
### Create a Matrix
```php
setData([
[1, 2, 3],
[4, 5, 6]
]);
```

### Simple Operations

#### Add
```php
add($matrixB);

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

#### Subtract
```php
subtract($matrixB);

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

#### Multiply
```php
subtract($matrixB);

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

### Scalar Operations

#### Scalar Multiply
```php
scalarMultiply(5);

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

#### Scalar Division
```php
scalarDivide(5);

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

### Custom Operations

#### Scalar Operations
```php
scalarMatrixOperation(function($element) {
return $element == 1 ? 0 : 1;
});

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

#### "Synchronous" Operations
```php
synchronousMatrixOperation($matrixB, function($left, $right) {
return intval($left ^ $right);
});

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

### Transformation

#### Transpose
```php
transpose();

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