Пример #1
0
 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));
 }
Пример #2
0
        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);
        }