inline void Lt1BackSubstitute(const MatrixTemplate<T>& a, const MatrixTemplate<T>& b, MatrixTemplate<T>& x) { if(x.isEmpty()) x.resize(a.n,b.n); else Assert(x.m == a.n && x.n == b.n); for(int i=0;i<x.n;i++) { VectorTemplate<T> xi,bi; x.getColRef(i,xi); b.getColRef(i,bi); Lt1BackSubstitute(a,bi,xi); } }
bool LDLDecomposition<T>::backSub(const MatrixT& B, MatrixT& X) const { X.resize(B.m,B.n); MatrixT temp(B.m,B.n); L1BackSubstitute(LDL,B,temp); VectorT tempi; bool res=true; for(int i=0;i<temp.n;i++) { temp.getColRef(i,tempi); if(!DBackSub(tempi,tempi)) res=false; } Lt1BackSubstitute(LDL,temp,X); return res; }
void LDLDecomposition<T>::LTBackSub(const VectorT& b, VectorT& x) const { Assert(b.n == LDL.n); x.resize(LDL.n); Lt1BackSubstitute(LDL,b,x); }