Skip to content

Instantly share code, notes, and snippets.

@inspirit
Created June 21, 2011 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inspirit/1038841 to your computer and use it in GitHub Desktop.
Save inspirit/1038841 to your computer and use it in GitHub Desktop.
Solve MxN system using LU Decomposition
/**
* LU decomposition/solve is used for NxN (square) matrices
* but using additional computations we can use LU decomposition
* to solve MxN system (since LU routines less computation expensive)
*/
// u can find LU and MatrixMath Classes at my Google repo
var lu:LU = new LU();
// A:B - system
// m - rows; n - cols;
// x - solution
function LUSolveMxN(A:Vector.<Number>, m:int, n:int, x:Vector.<Number>, B:Vector.<Number>):Boolean
{
var At:Vector.<Number> = new Vector.<Number>((m*n), true);
var AtA:Vector.<Number> = new Vector.<Number>((n*n), true);
var AtB:Vector.<Number> = new Vector.<Number>(n, true);
MatrixMath.transposeMat( A, At, m, n );
MatrixMath.multMat( At, A, AtA, n, m, n );
MatrixMath.multMat( At, B, AtB, n, m, 1);
// bad matrix
if( !lu.solve(AtA, n, x, AtB) ) return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment