Hi,
PJSR implements Gauss-Jordan elimination, which can be used for matrix inversion and to solve systems of linear equations. As Mike has pointed out, decomposition methods are more efficient to solve linear systems. However, Gauss-Jordan is stable and rock-solid and, if this is not a really critical part of your implementation, and/or if the problem that you are trying to solve isn't very large, it does the job in a straightforward way. Also, Gauss-Jordan is the method of choice if you need both the inverse matrix and the solution.
Example snippet for matrix inversion:
function printMatrix( M, name )
{
if ( name )
console.writeln( name, ':' );
for ( var i = 0; i < M.rows; ++i )
{
for ( var j = 0; j < M.cols; ++j )
console.write( format( "%12g", M.at( i, j ) ) );
console.writeln();
}
}
var A = new Matrix( 1, 2, 3,
0, 1, 4,
5, 6, 0 );
var Ai = A.inverse();
printMatrix( A, "A" );
printMatrix( Ai, "Ai" );
Example to solve a linear system:
/* Solve:
*
* x + y + z = 5
* 2*x + 3*y + 5*z = 8
* 4*x + 5*z = 2
*/
var X = new Matrix( 1, 1, 1,
2, 3, 5,
4, 0, 5 );
var Y = new Matrix( 0, 0, 5,
0, 0, 8,
0, 0, 2 );
var R = Math.solve( X, Y );
// R[0] is the inverse of matrix X
// Last column of R[1] is the solution vector
printMatrix( R[1], "R" ); // x=3 y=4 z=-2
There is also a Math.svd() method that computes the singular value decomposition of a matrix. I can also put an example of this routine, if necessary.
The next versions of PCL and PJSR extend the Vector and Matrix classes and objects considerably. There is no determinant calculation function for Matrix because we don't need it for image processing purposes (we only need to know if the determinant exists, actually), but we can implement one if required.