public static MyMatrix <T> operator -(MyMatrix <T> firstMatrix, MyMatrix <T> secondMatrix) { if ((firstMatrix.Rows == secondMatrix.Rows) && (firstMatrix.Columns == secondMatrix.Columns)) { MyMatrix <T> temp = new MyMatrix <T>(firstMatrix.Rows, firstMatrix.Columns); for (int i = 0; i < firstMatrix.Rows; i++) { for (int j = 0; j < firstMatrix.Columns; j++) { temp.Matrix[i, j] = (dynamic)firstMatrix.Matrix[i, j] - (dynamic)secondMatrix.Matrix[i, j]; } } return(temp); } return(new MyMatrix <T>(1, 1)); }
public static MyMatrix <T> operator *(MyMatrix <T> firstMatrix, MyMatrix <T> secondMatrix) { MyMatrix <T> result = new MyMatrix <T>(firstMatrix.Rows, secondMatrix.Columns); for (int i = 0; i < firstMatrix.Rows; i++) { for (int j = 0; j < secondMatrix.Columns; j++) { T[] instance = new T[firstMatrix.Rows]; instance[0] = new T(); for (int k = 0; k < secondMatrix.Rows; k++) { instance[0] = (dynamic)instance[0] + (dynamic)firstMatrix.Matrix[i, k] * (dynamic)secondMatrix.Matrix[k, j]; } result.Matrix[i, j] = (dynamic)instance[0]; } } return(result); }