24 #define GRT_DLL_EXPORTS 25 #include "LUDecomposition.h" 29 LUDecomposition::LUDecomposition(
const MatrixFloat &a) : sing(false){
31 errorLog.
setKey(
"[ERROR LUDecomposition]");
32 warningLog.setKey(
"[WARNING LUDecomposition]");
39 const Float TINY=1.0e-20;
40 unsigned int i,imax,j,k;
48 if ((temp=fabs( lu[i][j] )) > big) big=temp;
51 errorLog <<
"Error in LUDecomposition constructor, big == 0.0" << std::endl;
59 temp=vv[i]*fabs(lu[i][k]);
68 lu[imax][j] = lu[k][j];
75 if (lu[k][k] == 0.0) lu[k][k] = TINY;
76 for (i=k+1; i<N; i++) {
77 temp = lu[i][k] /= lu[k][k];
79 lu[i][j] -= temp * lu[k][j];
85 LUDecomposition::~LUDecomposition(){
91 int i=0,ii=0,ip=0,j=0;
95 if (b.size() != N || x.size() != N){
96 errorLog <<
"solve_vector(const VectorFloat &b,VectorFloat &x) - the size of the two vectors does not match!" << std::endl;
99 for (i=0;i<n;i++) x[i] = b[i];
105 for (j=ii-1;j<i;j++) sum -= lu[i][j] * x[j];
110 for (i=n-1;i>=0;i--) {
112 for (j=i+1;j<n;j++) sum -= lu[i][j] * x[j];
113 x[i] = sum / lu[i][i];
123 errorLog <<
"solve(const MatrixFloat &b,MatrixFloat &x) - the size of the two matrices does not match!" << std::endl;
127 for (
unsigned int j=0; j<m; j++) {
128 for(
unsigned int i=0; i<N; i++) xx[i] = b[i][j];
130 for(
unsigned int i=0; i<N; i++) x[i][j] = xx[i];
140 for (j=0;j<N;j++) ainv[i][j] = 0.0;
143 return solve(ainv,ainv);
146 Float LUDecomposition::det()
149 for (
unsigned int i=0;i<N;i++) dd *= lu[i][i];
161 sdp += (LongFloat) aref[i][j] * (LongFloat)x[j];
164 if( !solve_vector(r,r) ){
167 for (i=0;i<N;i++) x[i] -= r[i];
171 bool LUDecomposition::getIsSingular(){
virtual bool setKey(const std::string &key)
sets the key that gets written at the start of each message, this will be written in the format 'key ...
unsigned int getNumRows() const
unsigned int getNumCols() const
virtual bool resize(const unsigned int r, const unsigned int c)