views:

607

answers:

2

Does anyone know where I might find a PHP matrix math library which is still actively maintained?

I need to be able to do the basic matrix operations like reduce, transpose (including non-square matrices), invert, determinant, etc.

This question was asked in the past, then closed with no answers. Now I need an answer to the same question. See these links to related questions:

http://stackoverflow.com/questions/428473/matrix-artihmetic-in-php http://stackoverflow.com/questions/435074/matrix-arithmetic-in-php-again

I was in the process of installing the pear Math_Matrix library when I saw these and realized it wouldn't help me. (Thanks Ben for putting that comment about transpose in your question.)

I can code this stuff myself, but I would make me happier to see that there is a library for this somewhere.

+2  A: 

You might do better to do your matrix manipulations in another language and call that code from PHP. The PHP community isn't typically concerned with matrix computation, so I imagine it will be challenging to find what you want. But there are plenty of math libraries in other languages. For example, you might try Python (SciPy), though I don't know how hard it is to mix PHP and Python. I don't know PHP, but most languages have a way to call C, and from C you could call the Gnu Scientific Library, for example.

By the way, there's hardly ever a reason to invert a matrix. Most problems that appear to require matrix inversion actually require solving linear systems. The latter is more stable. Also, some libraries may not have a matrix inversion routine per se because they assume people will use a factorization routine (e.g. Cholesky) and repeated solve systems of equations.

John D. Cook
I used python, launched using shell_exec from the php. It was a little tricky to get the linear algebra module right. There are two versions, one with SciPy and one with the older Numeric package. I had Numeric pre-installed with python, but I ended up making it work with both versions.
Mnebuerquo
A: 

It is not really a library but there is a lot of usefull php math code (including operations on matrices) on this page:

http://www.phpmath.com/home

I hope this will help

Amorphous