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

https://github.com/tdebatty/php-vector-matrix

A PHP library for vectors and matrices algebra
https://github.com/tdebatty/php-vector-matrix

Last synced: 9 months ago
JSON representation

A PHP library for vectors and matrices algebra

Awesome Lists containing this project

README

          

php-vector-matrix
=================

A PHP library for vectors and matrices algebra

Usage
-----

```php
add($v2);
$v3->display();

// If you have PECL extension operator installed,
// this returns a Vector with value (5,7,9)
$v4 = $v1 - $v2;
var_dump($v4);

var_dump($v1 - 1);

var_dump($v1 . $v2); // Dot product

var_dump($v1 * $v2); // Cross product

$v2_normalized = $v2->normalize();
var_dump($v2_normalized);
var_dump($v2_normalized->length()); // Should be 1!

$v4 = new Vector(1, 2, 5, 4.2, 8, 5, 10.9, 1, 7, 4);
var_dump($v4->mean());
var_dump($v4->standardDeviation());

$v5 = $v4 - $v4->mean();
$v5 = $v5 / $v4->standardDeviation();

var_dump($v5);
var_dump($v5->mean()); // Should be close to 0
var_dump($v5->standardDeviation()); // Should be close to 1
```