//--------------------------------------------------------- bool CSG_Matrix::Add_Row(double *Data) { if( Add_Rows(1) ) { Set_Row(m_ny - 1, Data); return( true ); } return( false ); }
/** * Sets the number of rows to nRows. Values will be preserved. * Returns true if successful. */ bool CSG_Vector::Set_Rows(int nRows) { if( nRows > Get_N() ) { return( Add_Rows(nRows - Get_N()) ); } if( nRows < Get_N() ) { return( Del_Rows(Get_N() - nRows) ); } return( true ); }
//--------------------------------------------------------- bool CSG_Matrix::Set_Rows(int nRows) { if( nRows > m_ny ) { return( Add_Rows(nRows - m_ny) ); } if( nRows < m_ny ) { return( Del_Rows(m_ny - nRows) ); } return( true ); }
// perform Guass-Jordanian elimination: The matrix will become // it's inverse void XSQUARE_MATRIX::Inverse_GJ(void) { if (m_lpdValues) { XSQUARE_MATRIX cI(m_uiN); cI.Identity(); // allocate work space double dScalar; // Using row reduction, reduce the source matrix to the identity, // and the identity will become A^{-1} for (unsigned int uiRow = 0; uiRow < m_uiN; uiRow++) { if (m_lpdValues[uiRow * m_uiN + uiRow] == 0.0) { for (unsigned int uiRowInner = uiRow + 1; uiRowInner < m_uiN; uiRowInner++) { if (m_lpdValues[uiRowInner * m_uiN + uiRow] != 0.0) { Swap_Rows(uiRow,uiRowInner); cI.Swap_Rows(uiRow,uiRowInner); } } } dScalar = 1.0 / m_lpdValues[uiRow * m_uiN + uiRow]; Scale_Row(uiRow,dScalar); cI.Scale_Row(uiRow,dScalar); for (unsigned int uiRowInner = 0; uiRowInner < m_uiN; uiRowInner++) { double dRow_Scalar = -m_lpdValues[uiRowInner * m_uiN + uiRow]; if (uiRowInner != uiRow) { cI.Add_Rows(uiRowInner,uiRow,dRow_Scalar,false); Add_Rows(uiRowInner,uiRow,dRow_Scalar,true); } } } // copy result into current matrix *this = cI; } }