1. Go to this page and download the library: Download lotltd/php-vector-matrix library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lotltd / php-vector-matrix example snippets
use \webd\vectors\Vector;
$v1 = new Vector(1,2,3);
$v2 = new Vector(4,5,10);
$v3 = $v1->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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.