Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. /***********************
  2.  
  3. * RowEchelon: Check if the matrix is row echelon or reduced row echelon format
  4. * @author: Kelsey Scheurich
  5. * @return: bool
  6.  
  7. ********************/
  8. void CGauss::RowEchelon( HWND _hDlg )
  9. {
  10. // Create bool to store if row is allowed
  11. bool bAllowedZeroRow = true;
  12.  
  13. /////////// Reduced Row Echelon //////////////
  14. // Create floats to store matrix variables
  15. float fA;
  16. float fB;
  17. float fC;
  18. float fD;
  19.  
  20. // Loop through 3 rows
  21. for( int i = 2 ; i >= 0; i-- )
  22. {
  23. // For each item in the row
  24. for( int j = 0; j <= 4; ++j )
  25. {
  26. // Set as matrix value
  27. fA = m_fMatrix[ i ][ 0 ];
  28. fB = m_fMatrix[ i ][ 1 ];
  29. fC = m_fMatrix[ i ][ 2 ];
  30. fD = m_fMatrix[ i ][ 3 ];
  31.  
  32. // If they are all 0
  33. if( ( fA == 0 ) && ( fB == 0 ) && ( fC == 0 ) && ( fD == 0 ) )
  34. {
  35. // Row is full of 0
  36. if( bAllowedZeroRow == false)
  37. {
  38. // row is not allowed
  39. return;
  40. }
  41. }
  42. else
  43. {
  44. // Row is not allowed
  45. bAllowedZeroRow = false;
  46. }
  47. }
  48. }
  49.  
  50. // Create variables for current value, found, leading one index
  51. int iRowAboveLeadingOneIndex = ( -1 );
  52. float fCurrentValue;
  53. bool bFoundReduced = true;
  54. bool bAllowedNonZero;
  55.  
  56. // For each row
  57. for( int i = 0; i < 3; i++ )
  58. {
  59. // Set to true
  60. bAllowedNonZero = true;
  61. // For each item in the row
  62. for( int j = 0; j < 3; ++j )
  63. {
  64. // Get current value
  65. fCurrentValue = m_fMatrix[ j ][ i ];
  66.  
  67. // If it is 0, carry on
  68. if( fCurrentValue == 0 )
  69. {
  70. continue;
  71. }
  72. // Else if it is 1 and the one above is allowed to be non 0
  73. else if( ( fCurrentValue == 1 ) && ( i > iRowAboveLeadingOneIndex ) && bAllowedNonZero )
  74. {
  75. //Set to false and set to i
  76. iRowAboveLeadingOneIndex = i;
  77. bAllowedNonZero = false;
  78. }
  79. // Else is not echelon
  80. else
  81. {
  82. if( bAllowedNonZero )
  83. {
  84. bAllowedNonZero = false;
  85. }
  86. else
  87. {
  88. bFoundReduced = false;
  89. break;
  90. }
  91.  
  92. }
  93. }
  94. }
  95. // If have found reduces and the one above is not -1
  96. if( bFoundReduced && iRowAboveLeadingOneIndex != ( -1 ) )
  97. {
  98. // Open message box
  99. MessageBox( _hDlg, L"You have reached Reduced Row Echelon", L"Reduced Row Echelon", MB_ICONINFORMATION | MB_OK );
  100. return;
  101. }
  102. ///////////////// Row Echelon /////////////////
  103. // Set back to -1
  104. iRowAboveLeadingOneIndex = ( -1 );
  105. // Loop through matrix
  106. for( int i = 0; i < 3; i++ )
  107. {
  108. for( int j = 0; j < 3; j++ )
  109. {
  110. // Get matrix value
  111. fCurrentValue = m_fMatrix[ i ][ j ];
  112.  
  113. // If it is 0, continue
  114. if( fCurrentValue == 0 )
  115. {
  116. continue;
  117. }
  118. // Else if its not 0
  119. else if( fCurrentValue != 0 )
  120. {
  121. // Check if i is 0 & j is smaller than row above
  122. if( i == 0 || j > iRowAboveLeadingOneIndex )
  123. {
  124. // Set to j
  125. iRowAboveLeadingOneIndex = j;
  126. break;
  127. }
  128. else
  129. {
  130. return;
  131. }
  132. }
  133. else
  134. {
  135. return;
  136. }
  137. }
  138. }
  139. // If row above is -1
  140. if( iRowAboveLeadingOneIndex != ( -1 ) )
  141. {
  142. // Reached row echelon
  143. MessageBox( _hDlg, L"You have reached Row Echelon", L"Row Echelon", MB_ICONINFORMATION | MB_OK );
  144. }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement