Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/aboks/power-iteration

Implementation of the Power Iteration method for finding eigenvalues of a matrix, using math-php
https://github.com/aboks/power-iteration

eigenvalues eigenvectors linear-algebra mathematics php

Last synced: about 2 months ago
JSON representation

Implementation of the Power Iteration method for finding eigenvalues of a matrix, using math-php

Awesome Lists containing this project

README

        

![Continuous Integration](https://github.com/aboks/power-iteration/workflows/Continuous%20Integration/badge.svg)
[![Latest Stable Version](https://poser.pugx.org/aboks/power-iteration/v/stable)](https://packagist.org/packages/aboks/power-iteration)

PowerIteration
==============
Implementation of the Power Iteration method for finding (dominant) eigenvalues and the corresponding eigenvectors of a matrix, using the excellent [math-php](https://github.com/markrogoyski/math-php) library.

Installation
------------
Install using composer:
```
$ composer require aboks/power-iteration
```

Basic usage
-----------
```php
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
```

Advanced usage
--------------

### Calculating the least dominant eigenpair

In most situations, one is interested in the dominant eigenvalue and its corresponding eigenvector. It is also possible to calculate the least dominant eigenpair however:
```php
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
```

Customizations
--------------

### Stopping criterion

By default, the power iteration runs for 1000 iterations. The stopping criterion can be altered by passing an instance of `StoppingCriterion` as the first argument to `PowerIteration`:
```php