示例#1
0
        //------------------------------------------------------------------------------------------
        //Поэлемнетное деление
        public static RealMatrix GetElementwiseDivision(
            IntegerMatrix dividendMatrix,
            IntegerMatrix dividerMatrix
            )
        {
            bool equalSize = IntegerMatrix.IsEqualMatricesSize(dividendMatrix, dividerMatrix);

            if (!equalSize)
            {
                throw new MatrixException();
            }
            int        rowCount    = dividendMatrix.rowCount;
            int        columnCount = dividerMatrix.columnCount;
            RealMatrix newMatrix   = new RealMatrix(rowCount, columnCount);

            for (int row = 0; row < rowCount; row++)
            {
                for (int column = 0; column < columnCount; column++)
                {
                    double dividend = dividendMatrix[row, column];
                    double divider  = dividerMatrix[row, column];
                    double value    = Convert.ToDouble(dividend) / Convert.ToDouble(divider);
                    newMatrix[row, column] = value;
                }
            }
            return(newMatrix);
        }
示例#2
0
        //------------------------------------------------------------------------------------------
        //Разность матриц
        public static IntegerMatrix operator -(IntegerMatrix matrixOne, IntegerMatrix matrixTwo)
        {
            int rowCountMatrixOne    = matrixOne.rowCount;
            int rowCountMatrixTwo    = matrixTwo.rowCount;
            int columnCountMatrixOne = matrixOne.columnCount;
            int columnCountMatrixTwo = matrixTwo.columnCount;

            bool sizeEquality = IntegerMatrix.IsEqualMatricesSize(matrixOne, matrixTwo);

            if (!sizeEquality)
            {
                throw new MatrixException();
            }

            IntegerMatrix resultMatrix =
                new IntegerMatrix(rowCountMatrixOne, columnCountMatrixOne);

            for (int row = 0; row < resultMatrix.rowCount; row++)
            {
                for (int column = 0; column < resultMatrix.columnCount; column++)
                {
                    resultMatrix[row, column] =
                        matrixOne[row, column] - matrixTwo[row, column];
                }
            }
            return(resultMatrix);
        }