/// <summary> /// Elementary row operation one, interchange two rows /// </summary> /// <param name="rowOneIndex">Row one index</param> /// <param name="rowTwoIndex">Row two index</param> public static void EROOne(this RealMatrix matrix, int rowOneIndex, int rowTwoIndex) { var rowOne = matrix.GetRow(rowOneIndex); var rowTwo = matrix.GetRow(rowTwoIndex); for (int i = 0; i < matrix.ColumnCount; i++) { matrix.M[rowOneIndex][i] = rowTwo.V[i]; matrix.M[rowTwoIndex][i] = rowOne.V[i]; } if (matrix.IsAugmentedMatrix) { var augmentedRowOne = matrix.GetAugmentedRow(rowOneIndex); var augmentedRowTwo = matrix.GetAugmentedRow(rowTwoIndex); for (int i = 0; i < matrix.AugmentedColumnCount; i++) { matrix.B[rowOneIndex][i] = augmentedRowOne.V[i]; matrix.B[rowTwoIndex][i] = augmentedRowTwo.V[i]; } } matrix.MatrixElementsChanged(); //TODO //If two rows of A are interchanged to produce a matrix B, then det(B) = //− det(A). }
/// <summary> /// Elemental row operation two, multiply one row with a constant /// </summary> /// <param name="rowIndex">Row to multiplt</param> /// <param name="constant">Multiply row with this constant</param> public static void EROTwo(this RealMatrix matrix, int rowIndex, IR.RealNumber constant) { if (constant == 0) { return; } var row = matrix.GetRow(rowIndex); row.ElementMultiplication(constant); matrix.WriteOnRow(row, rowIndex); if (matrix.IsAugmentedMatrix) { var augmentedRow = matrix.GetAugmentedRow(rowIndex); augmentedRow.ElementMultiplication(constant); matrix.WriteOnRow(augmentedRow, rowIndex, isAugmentedRow: true); } matrix.MatrixElementsChanged(); //TODO //If a row of A is multiplied by a real number α to produce a matrix B, then //det(B) = αdet(A) }