void ToEchelonForm() { int rowCount = _a.RowCount; int colCount = _a.ColCount; var matrix = new IndexMatrix(_a); for (int i = 0, j = 0; i < rowCount && j < colCount; i++, j++) { int currentRow = i; if (!FindPivotIndex(matrix, ref i, ref j)) { break; } if (i > currentRow) { matrix.SwapRows(i, currentRow); i = currentRow; } double pivotCoeff = matrix[i, j]; for (int ii = i + 1; ii < rowCount; ii++) { double coeff = matrix[ii, j]; if (coeff == 0.0) { continue; } double multiple = coeff / pivotCoeff; matrix.AddRowMultiple(ii, -multiple, i); matrix[ii, j] = 0.0; } } foreach (var c in matrix.CoefficientIterator()) { _a[c] = c.Value; } }
static void Main() { Console.WriteLine("Enter number of rows"); int rows = int.Parse(Console.ReadLine()); Console.WriteLine("Enter number of columns"); int columns = int.Parse(Console.ReadLine()); IndexMatrix<int> matrix = new IndexMatrix<int>(rows, columns); Console.WriteLine("Enter elements"); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { matrix[row, column] = int.Parse(Console.ReadLine()); } } Console.WriteLine("Enter row"); int elementRow = int.Parse(Console.ReadLine()); Console.WriteLine("Enter column"); int elementColumn = int.Parse(Console.ReadLine()); Console.WriteLine("Element on position [{0}, {1}] has value {2}", elementRow, elementColumn, matrix[elementRow, elementColumn]); }