Mnebuerquo - 1 year ago 56

PHP Question

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:

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.

Answer Source

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.