Quite fast library for computing power of matrix using php

Still about Matrix, since lately I handle a lot of web-based projects that involving Matrix computations, maybe someday you’ll need this.
I’m in need of this kind of library when creating web-based ANP (Analytic Network Process) problem solver where you have to power the weighted supermatrix with some high integer number to gain the limit supermatrix.

Here’s the codes inside the library, you can save it to whatever php file:

(I’m sorry I don’t post the full source code on this post, WordPress always messed up the code because it contains ‘<‘ and ‘>’)

How to use it?
As simple as this:

Comparison to MATLAB
We’ll compare MATLAB result and our library result for the correctness and calculation speed.
The matrix will be taken from a CSV file and will be 15×15 in size. We will power this matrix to 512.
This is the MALTAB code used:

This is the partial screenshot of the MATLAB’s code result

power of matrix using MATLAB

power of matrix using MATLAB result

And finally our PHP code:
You can see it here: http://pastebin.com/x3hFi6tm
I won’t take the result screenshot as you can try it on http://demo.ahowto.net/matrix_power.php

If you run the MATLAB code and the PHP code, you’ll see that our PHP code yield the same result as the MATLAB code but it run much faster than the MATLAB (both already timed in miliseconds)! I absolutely don’t know why powering matrix using PHP is faster than using MATLAB but I’m happy with the result. 😀

Leave a Reply

%d bloggers like this: