public static IntMatrix E(uint i, uint j, uint rowsAndCols) { var newM = new IntMatrix(rowsAndCols, rowsAndCols); newM[i, j] = 1; return(newM); }
public IntMatrix MultiplyRow(uint r, int factor) { var newM = IntMatrix.FromArray(M); for (uint c = 0; c < newM.Cols; c++) { newM[r, c] *= factor; } return(newM); }
public IntMatrix AddRows(uint rSrc, uint rDst, int factor) { var newM = IntMatrix.FromArray(M); for (uint c = 0; c < newM.Cols; c++) { newM[rDst, c] += factor * newM[rSrc, c]; } return(newM); }
public IntMatrix SwapRows(uint r1, uint r2) { var newM = IntMatrix.FromArray(M); for (uint c = 0; c < newM.Cols; c++) { (newM[r1, c], newM[r2, c]) = (newM[r1, c], newM[r2, c]); } return(newM); }
public static IntMatrix EinheitsMatrix(uint i) { var newM = new IntMatrix(i, i); for (uint j = 0; j < i; j++) { newM[j, j] = 1; } return(newM); }
public static IntMatrix FromArray(int[][] array) { var newM = new IntMatrix((uint)array.GetLength(0), (uint)array[0].GetLength(0)); for (int r = 0; r < array.GetLength(0); r++) { for (int c = 0; c < array.GetLength(1); c++) { newM.M[r, c] = array[r][c]; } } return(newM); }
public static IntMatrix FromArray(int[] array, uint cols) { var newM = new IntMatrix((uint)array.GetLength(0) / cols, cols); for (uint r = 0; r < array.GetLength(0); r++) { for (uint c = 0; c < array.GetLength(0); c++) { newM[r, c] = array[r * cols + r]; } } return(newM); }
public static IntMatrix operator *(int factor, IntMatrix a) { IntMatrix newM = new IntMatrix(a.Rows, a.Cols); for (uint r = 0; r < a.Rows; r++) { for (uint c = 0; c < a.Cols; c++) { newM.M[r, c] = a[r, c] * factor; } } return(newM); }
public static IntMatrix operator -(IntMatrix a, IntMatrix b) { if (a.Rows != b.Rows || a.Cols != b.Cols) { throw new System.NotSupportedException(); } else { IntMatrix newM = new IntMatrix(a.Rows, a.Cols); for (int r = 0; r < a.Cols; r++) { for (int c = 0; c < a.Cols; c++) { newM.M[r, c] = a.M[r, c] - b.M[r, c]; } } return(newM); } }
public static IntMatrix operator *(IntMatrix a, IntMatrix b) { if (a.Cols != b.Rows) { throw new System.NotSupportedException(); } else { IntMatrix newM = new IntMatrix(a.Rows, b.Cols); for (int r = 0; r < a.Rows; r++) { for (int c = 0; c < b.Cols; c++) { for (int x = 0; x < a.Cols; x++) { newM.M[r, c] += a.M[r, x] * b.M[x, c]; // } } } return(newM); } }