/// <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). }
public static RealMatrix GetTranspose(this RealMatrix matrix) { var columnVectors = new List <ColumnVector>(); for (int i = 0; i < matrix.RowCount; i++) { columnVectors.Add(matrix.GetRow(i).Transpose()); } return(new RealMatrix(columnVectors)); }
public static RealMatrix DotProduct(this RealMatrix a, RealMatrix b) { if (a.ColumnCount != b.RowCount) { Console.WriteLine("For matrix A column count not equal to B row count."); return(null); } var result = new RealMatrix(a.RowCount, b.ColumnCount); for (int i = 0; i < a.RowCount; i++) { for (int j = 0; j < a.ColumnCount; j++) { result.M[i][j] = a.GetRow(i).DotProduct(b.GetColumn(j)); } } return(result); }
/// <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) }