| 612 | //---------------------------------------------------------------------------- |
| 613 | template <class Real> |
| 614 | bool LinearSystem<Real>::SolveBanded (const BandedMatrix<Real>& rkA, |
| 615 | const Real* afB, Real* afX) |
| 616 | { |
| 617 | BandedMatrix<Real> kTmp = rkA; |
| 618 | int iSize = rkA.GetSize(); |
| 619 | size_t uiSize = iSize*sizeof(Real); |
| 620 | System::Memcpy(afX,uiSize,afB,uiSize); |
| 621 | |
| 622 | // forward elimination |
| 623 | int iRow; |
| 624 | for (iRow = 0; iRow < iSize; iRow++) |
| 625 | { |
| 626 | if (!ForwardEliminate(iRow,kTmp,afX)) |
| 627 | { |
| 628 | return false; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | // backward substitution |
| 633 | for (iRow = iSize-2; iRow >= 0; iRow--) |
| 634 | { |
| 635 | int iColMin = iRow + 1; |
| 636 | int iColMax = iColMin + kTmp.GetUBands(); |
| 637 | if (iColMax > iSize) |
| 638 | { |
| 639 | iColMax = iSize; |
| 640 | } |
| 641 | for (int iCol = iColMin; iCol < iColMax; iCol++) |
| 642 | { |
| 643 | afX[iRow] -= kTmp(iRow,iCol)*afX[iCol]; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | return true; |
| 648 | } |
| 649 | //---------------------------------------------------------------------------- |
| 650 | template <class Real> |
| 651 | bool LinearSystem<Real>::ForwardEliminate (int iReduceRow, |