Created
June 21, 2011 20:39
-
-
Save inspirit/1038841 to your computer and use it in GitHub Desktop.
Solve MxN system using LU Decomposition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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