PHP Classes

PHP Matrix Arithmetic Library: Perform math operations with matrices

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 280 All time: 7,617 This week: 560Up
Version License PHP version Categories
m3 2.0.0Custom (specified...5.3Algorithms, PHP 5, Math
Description 

Author

This class can perform math operations with matrices.

It can store the values of a bidimensional matrix taking the initial values from arrays.

The class can also perform math operations with the matrix like addition, subtraction, multiplication, division, determinant, eigen values, inverse, factorizations, decomposition, etc..

Innovation Award
PHP Programming Innovation award nominee
June 2017
Number 6
Matrices are often used in complex scientific math operations.

This class can perform many of the basic matrix operations.

Manuel Lemos
Picture of zinsou A.A.E.Moïse
  Performance   Level  
Name: zinsou A.A.E.Moïse is available for providing paid consulting. Contact zinsou A.A.E.Moïse .
Classes: 50 packages by
Country: Benin Benin
Age: 34
All time rank: 6761 in Benin Benin
Week rank: 197 Up1 in Benin Benin Equal
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

Recommendations

Perform matrix arithmetic
I need to compute determinats

a simple PHP class to perform singular values decomposition
i need a PHP implementation of SVD decomposition

Example

<?php
require_once('./matrix.class.php');
echo
'<h2>Example of matrix:<img src="./example.png"/></h2>';
echo
'<pre>';
$hous=new Matrix(array(array(4,-30,60,-35),array(-30,300,-675,420),array(60,-675,1620,-1050),array(-35,420,-1050,700)));
echo
'<h2>Calculation of the determinant</h2>';
var_dump($hous->getDet());

echo
'<h2>Calculation of eigenvalues</h2>';

var_dump($hous->getEigens());
echo
'<h2>Calculation of the inverse</h2>';

var_dump($hous->lu_reversed());
echo
'<h2>Different factorizations </h2>';

echo
'<h3>LU factorization </h3>';
$op=$hous->ludcmp2();
// var_dump($op);
$u=Matrix::Op($op['L'],$op['U'],'*');
var_dump($u);

echo
'<h3>Cholesky factorization </h3>';

$op=$hous->CholeskyLLTdcmp();
// var_dump($op);
$u=Matrix::Op($op,$op->transposed(),'*');
var_dump($u);

echo
'<h3>Singular values decomposition </h3>';

$svd=$hous->svdcmp();
// var_dump($svd);

$a=Matrix::Op(Matrix::Op($svd['U'],$svd['W'],'*'),$svd['V']->transposed(),'*');

var_dump($a);

echo
'<h3>QR factorization </h3>';
$op=$hous->householdertransformations();
// var_dump($op);
$u=Matrix::Op($op['Q'],$op['R'],'*');
var_dump($u);
echo
'<h2>Eigenvalues calculation </h2>';


$hous=new Matrix(array(array(2,-2,0),array(1,5,3),array(-2,1,4)));// must not use deflation on this because of complex eigenvalues
var_dump($hous->getEigens());

$hous=new Matrix(array(array(2,0,1,2),array(0,2,2,3),array(-1,0,0,1),array(3,1,-1,2)));// must not use deflation on this because of complex eigenvalues
var_dump($hous->getEigens());

$hous=new Matrix(array(array(5,4,2,1),array(0,1,-1,1),array(-1,-1,3,0),array(1,1,-1,2)));//but on this yes even if it is not symmetric
var_dump($hous->getEigens());

var_dump($hous->deflation());


var_dump($hous->inverseandshift(3));
var_dump($hous->inversepowerIteration());


Details

Bug reporting to leizmo@gmail.com

Screenshots (1)  
  • example.png
  Files folder image Files (7)  
File Role Description
Accessible without login Plain text file license Lic. license
Plain text file matrix.class.php Class matrix.class
Accessible without login Plain text file Matrix_class_package_english_doc.pdf Doc. Matrix class package english doc
Accessible without login Plain text file Matrix_class_package_french_doc.pdf Doc. Matrix class package french doc
Accessible without login Plain text file readme.txt Doc. read me
Accessible without login Plain text file test.php Example example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:280
This week:0
All time:7,617
This week:560Up