MatLabPHP
Some Math operations on PHP with MatLab syntaxis.
Requiring/Loading
If you're using Composer to manage dependencies, you can include the following in your composer.json file:
{
"require": {
"royopa/mat-lab-php": "dev-master"
}
}or
composer require royopa/mat-lab-php
Then, after running composer update or php composer.phar update, you can
load the class using Composer's autoloading:
require 'vendor/autoload.php';Otherwise, you can simply require the file directly:
require_once 'path/to/MatLabPHP/src/MatLabPHP.php';And in either case, I'd suggest using an alias.
use MatLabPHP\MatLabPHP as M;Methods
stringToVector()
$matLabPHP->stringToVector(string $str);- description
- Transform a vector in the format of [1 2 3] to an array(1,2,3);
- parameters
- Number, Vector or Matrix. Ex: 1 or [1 2 3] or [1 2 ; 3 4]
- return
- Array of Number, Vector or Matrix to operate in the class.
$matLabPHP = new MatLabPHP();
$matLabPHP->stringToVector("[3 1 2; 5 4 7; 6 9 7]");
//array(
0 => array(
0 => '3',
1 => '1',
2 => '2'
),
1 => array(
0 => '5',
1 => '4',
2 => '7'
),
2 => array(
0 => '6',
1 => '9',
2 => '7'
)
);eye()
$matLabPHP->eye($cols, $rows = 'eq');- description
- Create the identity matrix;
- parameters
- cols and rows.
- return
- Eye matrix
zeros()
$matLabPHP->zeros($cols, $rows = 'eq');- description
- Create the a matrix of zeros;
- parameters
- cols and rows.
- return
- Zero matrix
length()
$matLabPHP->length($vector, $ret = 0);- description
- Gives back the max between cols and rows of a matrix
- parameters
- vector or matrix
- return
- int
sum()
$matLabPHP->sum($sumA, $sumB);- description
- Sumes two matrix or vectors or numbers
- parameters
- two vector or matrix or numbers
- return
- result
mean()
$matLabPHP->mean($array);- description
- Calculate mean (simple arithmetic average).
- parameters
- array $values
- return
- string Mean
stddev()
$matLabPHP->stddev(array $a, $isSample = false);- description
- parameters
- return
variance()
$matLabPHP->variance($a, $isSample);- description
- parameters
- return
covariance()
$matLabPHP->covariance(array $x_values, array $y_values);- description
- parameters
- return
correlation()
$matLabPHP->correlation(array $x_values, array $y_values, $isSample = false);- description
- parameters
- return
Tests
From the project directory, tests can be ran using:
./vendor/bin/phpunit

