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
- Host: GitHub
- URL: https://github.com/devtronic/morpheus
- Owner: devtronic
- License: mit
- Created: 2017-06-24T12:35:57.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-08T08:45:50.000Z (almost 8 years ago)
- Last Synced: 2024-12-30T21:29:11.374Z (over 1 year ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/Devtronic/morpheus)
[](https://github.com/Devtronic/morpheus/blob/master/LICENSE)
[](https://travis-ci.org/Devtronic/morpheus)
[](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],
// ]
```