Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************
- * RowEchelon: Check if the matrix is row echelon or reduced row echelon format
- * @author: Kelsey Scheurich
- * @return: bool
- ********************/
- void CGauss::RowEchelon( HWND _hDlg )
- {
- // Create bool to store if row is allowed
- bool bAllowedZeroRow = true;
- /////////// Reduced Row Echelon //////////////
- // Create floats to store matrix variables
- float fA;
- float fB;
- float fC;
- float fD;
- // Loop through 3 rows
- for( int i = 2 ; i >= 0; i-- )
- {
- // For each item in the row
- for( int j = 0; j <= 4; ++j )
- {
- // Set as matrix value
- fA = m_fMatrix[ i ][ 0 ];
- fB = m_fMatrix[ i ][ 1 ];
- fC = m_fMatrix[ i ][ 2 ];
- fD = m_fMatrix[ i ][ 3 ];
- // If they are all 0
- if( ( fA == 0 ) && ( fB == 0 ) && ( fC == 0 ) && ( fD == 0 ) )
- {
- // Row is full of 0
- if( bAllowedZeroRow == false)
- {
- // row is not allowed
- return;
- }
- }
- else
- {
- // Row is not allowed
- bAllowedZeroRow = false;
- }
- }
- }
- // Create variables for current value, found, leading one index
- int iRowAboveLeadingOneIndex = ( -1 );
- float fCurrentValue;
- bool bFoundReduced = true;
- bool bAllowedNonZero;
- // For each row
- for( int i = 0; i < 3; i++ )
- {
- // Set to true
- bAllowedNonZero = true;
- // For each item in the row
- for( int j = 0; j < 3; ++j )
- {
- // Get current value
- fCurrentValue = m_fMatrix[ j ][ i ];
- // If it is 0, carry on
- if( fCurrentValue == 0 )
- {
- continue;
- }
- // Else if it is 1 and the one above is allowed to be non 0
- else if( ( fCurrentValue == 1 ) && ( i > iRowAboveLeadingOneIndex ) && bAllowedNonZero )
- {
- //Set to false and set to i
- iRowAboveLeadingOneIndex = i;
- bAllowedNonZero = false;
- }
- // Else is not echelon
- else
- {
- if( bAllowedNonZero )
- {
- bAllowedNonZero = false;
- }
- else
- {
- bFoundReduced = false;
- break;
- }
- }
- }
- }
- // If have found reduces and the one above is not -1
- if( bFoundReduced && iRowAboveLeadingOneIndex != ( -1 ) )
- {
- // Open message box
- MessageBox( _hDlg, L"You have reached Reduced Row Echelon", L"Reduced Row Echelon", MB_ICONINFORMATION | MB_OK );
- return;
- }
- ///////////////// Row Echelon /////////////////
- // Set back to -1
- iRowAboveLeadingOneIndex = ( -1 );
- // Loop through matrix
- for( int i = 0; i < 3; i++ )
- {
- for( int j = 0; j < 3; j++ )
- {
- // Get matrix value
- fCurrentValue = m_fMatrix[ i ][ j ];
- // If it is 0, continue
- if( fCurrentValue == 0 )
- {
- continue;
- }
- // Else if its not 0
- else if( fCurrentValue != 0 )
- {
- // Check if i is 0 & j is smaller than row above
- if( i == 0 || j > iRowAboveLeadingOneIndex )
- {
- // Set to j
- iRowAboveLeadingOneIndex = j;
- break;
- }
- else
- {
- return;
- }
- }
- else
- {
- return;
- }
- }
- }
- // If row above is -1
- if( iRowAboveLeadingOneIndex != ( -1 ) )
- {
- // Reached row echelon
- MessageBox( _hDlg, L"You have reached Row Echelon", L"Row Echelon", MB_ICONINFORMATION | MB_OK );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement