// *LU decomposition & determinant at O(n^3)* by Krzysztof Bosak, 1998.12.05 #include #include #include #define OUTPUT #define TRANSTABSEMI(x, y) (tab[(x)+indexy[(y)]]) // semi ==> possinle rows swapped, no columns swapping #define TRANSTABFULL(x, y) (tab[indexx[(x)]+indexy[(y)]]) // full ==> possible rows and columns swapping void testout(const int size, const double*const tab, const int*const indexy, const int*const indexx) { for(int x, y=0; yy) cout<<"0\t"; if(x==y) cout<<"1\t"; if(x=y) cout< void swap(typea &aa, typeb &bb) { typea temp=aa; aa=bb; bb=temp; } double DET(const int size, const double*const src) { if(size==1) return *src; const int max=size*size; bool sign=false; double*const tab=new double[max]; memcpy(tab, src, max*sizeof(double)); int*const indexy=new int[size<<1], *const indexx=indexy+size; int x, mul; for(x=0, mul=0; xmaxabs) { maxabs=value; ybest=ytest; } } if(maxabs==0.0) return 0; if(x!=ybest) swap(indexy[x], indexy[ybest]); if(int(x)!=ybest) sign=!sign; //////////////comment this region to avoid axial factor semi-selection for(int y=x+1; ymaxabs) { maxabs=value; xbest=xtest; ybest=ytest; } } } assert(maxabs>0); if(x!=ybest) swap(indexy[x], indexy[ybest]);//row swapping (~P1) if(x!=xbest) swap(indexx[x], indexx[xbest]);//column swapping (~P2)*/ //////////////comment this region to avoid axial factor full selection for(int y=x+1; y=0; y--) { result[y]=semi[y]; for(x=y+1; x