1. Go to this page and download the library: Download aboks/power-iteration 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/ */
aboks / power-iteration example snippets
use Aboks\PowerIteration\PowerIteration;
use MathPHP\LinearAlgebra\MatrixFactory;
$power_iteration = new PowerIteration();
$dominant_eigenpair = $power_iteration->getDominantEigenpair(MatrixFactory::create([
[2, 1],
[0, 1]
]));
var_dump($dominant_eigenpair->getEigenvalue()); // 2
var_dump($dominant_eigenpair->getEigenvector()); // Vector([1, 0]), or a scalar multiple
use Aboks\PowerIteration\PowerIteration;
use MathPHP\LinearAlgebra\Matrix;
$power_iteration = new PowerIteration();
$dominant_eigenpair = $power_iteration->getLeastDominantEigenpair(MatrixFactory::create([
[2, 1],
[0, 1]
]));
var_dump($dominant_eigenpair->getEigenvalue()); // 1
var_dump($dominant_eigenpair->getEigenvector()); // Vector([√2, -√2]), or a scalar multiple
use Aboks\PowerIteration\PowerIteration;
use Aboks\PowerIteration\StoppingCriterion\MaxIterations;
use Aboks\PowerIteration\StoppingCriterion\EigenvectorTolerance;
new PowerIteration(new MaxIterations(10)); // will stop after 10 iterations
new PowerIteration(new EigenvectorTolerance(0.01)); // will stop when ‖Av - λv‖ < 0.01
use Aboks\PowerIteration\PowerIteration;
use Aboks\PowerIteration\ScalingMethod\NormBased;
use Aboks\PowerIteration\Norm\MaxNorm;
new PowerIteration(null, new NormBased(new MaxNorm())); // will scale to a unit vector based on the max-norm
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.