lib/src/Workshop/LSquares.cpp
// this is written for square A
this is written for square A
this is written for square A
int  LSquares::gaussElim(Real** A,
                         Vector<Real>& rhs)
{
  int currRow = 0;
  int numRows = rhs.size();
  int numCols = rhs.size();
  for (int currCol = 0; currCol < numCols; ++currCol)
    {
      int pivot;
      findPivot(A,currCol, currRow,numRows,pivot);
      if (Abs(A[pivot][currCol]) > 1.0e-15)
      {
        swapRows(A,currRow,pivot,numCols);
        swapRows(rhs,currRow,pivot);
        Real Beta = A[currRow][currCol];
        Beta = 1.0/Beta;
        timesBeta(A,currRow,Beta, numCols);
        timesBeta(rhs,currRow,Beta);
        for (int rows = currRow; rows < numRows-1; ++rows)
        {
          Real alpha = -A[rows+1][currCol];
          addRows(A,rows+1,alpha,currRow,numCols);
          addRows(rhs,rows+1,alpha,currRow);
        }
        currRow += 1;
      }
      else
      {
         MayDay::Warning("small pivot in gaussElim");
      }
    }
  return 0;
}
int LSquares :: gaussElim ( Real * * A , Vector < Real > & rhs ) { int currRow = 0 ; int numRows = rhs . size ( ) ; int numCols = rhs . size ( ) ; for ( int currCol = 0 ; currCol < numCols ; ++ currCol ) { int pivot ; findPivot ( A , currCol , currRow , numRows , pivot ) ; if ( Abs ( A [ pivot ] [ currCol ] ) > 1.0e-15 ) { swapRows ( A , currRow , pivot , numCols ) ; swapRows ( rhs , currRow , pivot ) ; Real Beta = A [ currRow ] [ currCol ] ; Beta = 1.0 / Beta ; timesBeta ( A , currRow , Beta , numCols ) ; timesBeta ( rhs , currRow , Beta ) ; for ( int rows = currRow ; rows < numRows - 1 ; ++ rows ) { Real alpha = - A [ rows + 1 ] [ currCol ] ; addRows ( A , rows + 1 , alpha , currRow , numCols ) ; addRows ( rhs , rows + 1 , alpha , currRow ) ; } currRow += 1 ; } else { } } return 0 ; }
this is written for square A
this is written for square A
//   char* name = "A"; // output(numRows,numCols,A,name); // // output(numRows,numCols,A,name); // output(numRows,numCols,A,name); // MayDay::Warning("small pivot in gaussElim");