Example #1
0
            /// <summary>
            /// Finds the row with max value in submatrix and moves it to the top of it
            /// </summary>
            /// <param name="matrix">Whole matrix</param>
            /// <param name="topLeftCornerIndex">Top left corner index of the submatrix to find max</param>
            private static void MoveMaxValueSubmatrixRowToTop(double[,] matrix, int topLeftCornerIndex)
            {
                var maxValue          = Math.Abs(matrix[topLeftCornerIndex, topLeftCornerIndex]);
                var maxValueRowNumber = topLeftCornerIndex;

                for (var j = topLeftCornerIndex + 1; j < matrix.GetLength(0); ++j)
                {
                    var abs = Math.Abs(matrix[j, topLeftCornerIndex]);

                    if (abs > maxValue)
                    {
                        maxValue          = abs;
                        maxValueRowNumber = j;
                    }
                }

                if (maxValueRowNumber != topLeftCornerIndex)
                {
                    for (var j = 0; j < matrix.GetLength(1); ++j)
                    {
                        DoubleUtils.Swap(ref matrix[topLeftCornerIndex, j], ref matrix[maxValueRowNumber, j]);
                    }
                }
            }