Ejemplo n.º 1
0
        public static MatrixTable <T> operator -(MatrixTable <T> a, MatrixTable <T> b)
        {
            if (a.Matrix.GetLength(0) != b.Matrix.GetLength(0) || a.Matrix.GetLength(1) != b.Matrix.GetLength(1))
            {
                throw new ImpossibleMatrixOperationException();
            }
            int arraySizeX = a.Matrix.GetLength(0);
            int arraySizeY = a.Matrix.GetLength(1);
            var A          = new MatrixTable <T>(arraySizeX, arraySizeY);

            for (int i = 0; i < arraySizeY; i++)
            {
                for (int j = 0; j < arraySizeX; j++)
                {
                    A[i, j] = (dynamic)a[i, j] - b[i, j];
                }
            }

            return(A);
        }
Ejemplo n.º 2
0
        public static MatrixTable <T> operator *(MatrixTable <T> a, MatrixTable <T> b)
        {
            if (a.Matrix.GetLength(1) != b.Matrix.GetLength(0))
            {
                throw new ImpossibleMatrixOperationException();
            }
            var result = new MatrixTable <T>(a.Matrix.GetLength(0), b.Matrix.GetLength(1));

            for (int i = 0; i < a.Matrix.GetLength(0); i++)
            {
                for (int j = 0; j < b.Matrix.GetLength(1); j++)
                {
                    for (int k = 0; k < b.Matrix.GetLength(0); k++)
                    {
                        result[i, j] += (dynamic)a[i, k] * b[k, j];
                    }
                }
            }
            return(result);
        }