Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do PHP Matrix Operations in an easy/efficient way

I'm looking for a way to do Matrix operations in PHP in an easy/efficient way.

I want to be able to do the basic Matrix operations like Invert, Multiply, Determinant, add, subtract, Solving Linear Equations Ax=B, transpose, etc.

I'm looking at small sized matrices (The matrix I want to inverse are at most 100x100, and the vectors I want to multiply/transpose may get to be 1000x1).

I found a PEAR package Math_Matrix but it seems neglected (I develop with E_STRICT and it throws many deprecated warnings). The other links I have found seems mostly broken and un-updated.

I found the Lapack PHP package but it doesn't have other operations like multiplication or subtraction or transpose.

I know another option is to use integration with other software like Octave or Sage however we aren't quite sure we want to do this yet (the Financial team despises the Python syntax and the IT team it's worried about the Octave overhead).

Is there any stand alone library that anyone uses for this kind of matrix operations that has all the basic operations and it's updated?

like image 374
Jimmy Avatar asked Aug 21 '13 16:08

Jimmy


2 Answers

Take a look at http://projects.moongate.ro/octave-daemon/

Some of the features that may reduce overhead and convince the IT team:

  • The daemon is accessible via network, which means you can move all Octave processes on a separate server, should you decide you need to

  • Octave processes are persistent, which means that: any data that has been loaded or computed in the past will still be available for newly-connected clients

  • startup times for new Octave processes don't affect clients.

  • Provides conversions between Octave matrices and PHP arrays.

like image 52
Charity Leschinski Avatar answered Nov 13 '22 14:11

Charity Leschinski


I'm answering my own question about a year later.

We went for another option, we coded our own small library in C++ and we compiled it and added it to php as an extension. This produced the best performance and the code kept being pretty.

$inverted = my_matrix_invert($matrixArray);

People looking to do this kind of things should look here: http://www.php-cpp.com

like image 28
Jimmy Avatar answered Nov 13 '22 14:11

Jimmy