Exemplo n.º 1
0
        /// <summary>
        /// Returns <c>this</c> minus <c>m</c>.
        /// </summary>
        /// <param name="m">Matrix to be subtracted.</param>
        /// <returns><c>this - m</c></returns>
        /// <exception cref="MatrixDimensionMismatchException"> if <c>m</c> is not the same
        /// size as <c>this</c>.</exception>
        public DiagonalMatrix subtract(DiagonalMatrix m)
        {
            MatrixUtils.checkSubtractionCompatible(this, m);

            int dim = getRowDimension();

            double[] outData = new double[dim];
            for (int i = 0; i < dim; i++)
            {
                outData[i] = data[i] - m.data[i];
            }

            return(new DiagonalMatrix(outData, false));
        }
        /// <inheritdoc/>
        public RealMatrix subtract(RealMatrix m)
        {
            MatrixUtils.checkSubtractionCompatible(this, m);

            int        rowCount    = getRowDimension();
            int        columnCount = getColumnDimension();
            RealMatrix outp        = createMatrix(rowCount, columnCount);

            for (int row = 0; row < rowCount; ++row)
            {
                for (int col = 0; col < columnCount; ++col)
                {
                    outp.setEntry(row, col, getEntry(row, col) - m.getEntry(row, col));
                }
            }

            return(outp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns <c>this</c> minus <c>m</c>.
        /// </summary>
        /// <param name="m">Matrix to be subtracted.</param>
        /// <returns><c>this - m</c>.</returns>
        /// <exception cref="MatrixDimensionMismatchException"> if <c>m</c> is not the same
        /// size as <c>this</c>.</exception>
        public Array2DRowRealMatrix subtract(Array2DRowRealMatrix m)
        {
            MatrixUtils.checkSubtractionCompatible(this, m);

            int rowCount    = getRowDimension();
            int columnCount = getColumnDimension();

            double[][] outData = new double[rowCount][];
            for (int row = 0; row < rowCount; row++)
            {
                double[] dataRow    = data[row];
                double[] mRow       = m.data[row];
                double[] outDataRow = outData[row];
                for (int col = 0; col < columnCount; col++)
                {
                    outDataRow[col] = dataRow[col] - mRow[col];
                }
            }

            return(new Array2DRowRealMatrix(outData, false));
        }