public static MyMatrix Create(int row, int col) { MyMatrix m = new MyMatrix(); m._Row = row; m._Column = col; m.Matrix = new double[row][]; for (int i = 0; i < row; ++i) { m.Matrix[i] = new double[col]; } return(m); }
public static MyMatrix operator *(MyMatrix a, MyMatrix b) { if (a._Column != b._Row) { throw new Exception("Dimension mismatch"); } MyMatrix c = MyMatrix.Create(a._Row, b._Column); for (int i = 0; i < c._Row; i++) { for (int j = 0; j < c._Column; j++) { c.Matrix[i][j] = 0; for (int k = 0; k < b._Row; k++) //can use a._Col { c.Matrix[i][j] += a.Matrix[i][k] * b.Matrix[k][j]; } } } return(c); }