Java Array Multiply multiply(double[] multiplicand, double[] factor, double multiplicandAdjustment, double factorAdjustment)

Here you can find the source of multiply(double[] multiplicand, double[] factor, double multiplicandAdjustment, double factorAdjustment)

Description

Returns an array whose members are the product of the multiplicand array values and the factor array values.

License

Open Source License

Parameter

Parameter Description
multiplicand a parameter
factor a parameter
multiplicandAdjustment a parameter
factorAdjustment a parameter

Exception

Parameter Description
IllegalArgumentException if the two argument arrays are not the same length

Declaration

public static double[] multiply(double[] multiplicand, double[] factor, double multiplicandAdjustment,
        double factorAdjustment) 

Method Source Code

//package com.java2s;
/* ---------------------------------------------------------------------
 * Numenta Platform for Intelligent Computing (NuPIC)
 * Copyright (C) 2014, Numenta, Inc.  Unless you have an agreement
 * with Numenta, Inc., for a separate license for this software code, the
 * following terms and conditions apply:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero Public License for more details.
 *
 * You should have received a copy of the GNU Affero Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 *
 * http://numenta.org/licenses//* ww  w .  j  a v a 2  s. c o  m*/
 * ---------------------------------------------------------------------
 */

public class Main {
    /**
     * Returns an array whose members are the product of the multiplicand array
     * values and the factor array values.
     *
     * @param multiplicand
     * @param factor
     * @param multiplicandAdjustment
     * @param factorAdjustment
     *
     * @return
     * @throws IllegalArgumentException if the two argument arrays are not the same length
     */
    public static double[] multiply(double[] multiplicand, double[] factor, double multiplicandAdjustment,
            double factorAdjustment) {

        if (multiplicand.length != factor.length) {
            throw new IllegalArgumentException(
                    "The multiplicand array and the factor array must be the same length");
        }
        double[] product = new double[multiplicand.length];
        for (int i = 0; i < multiplicand.length; i++) {
            product[i] = (multiplicand[i] + multiplicandAdjustment) * (factor[i] + factorAdjustment);
        }
        return product;
    }

    /**
     * Returns an array whose members are the product of the multiplicand array
     * values and the factor array values.
     *
     * @param multiplicand
     * @param factor
     * @param multiplicand adjustment
     * @param factor       adjustment
     *
     * @return
     * @throws IllegalArgumentException if the two argument arrays are not the same length
     */
    public static double[] multiply(double[] multiplicand, int[] factor) {

        if (multiplicand.length != factor.length) {
            throw new IllegalArgumentException(
                    "The multiplicand array and the factor array must be the same length");
        }
        double[] product = new double[multiplicand.length];
        for (int i = 0; i < multiplicand.length; i++) {
            product[i] = (multiplicand[i]) * (factor[i]);
        }
        return product;
    }

    /**
     * Returns a new array containing the result of multiplying
     * each index of the specified array by the 2nd parameter.
     *
     * @param array
     * @param d
     * @return
     */
    public static int[] multiply(int[] array, int d) {
        int[] product = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            product[i] = array[i] * d;
        }
        return product;
    }

    /**
     * Returns a new array containing the result of multiplying
     * each index of the specified array by the 2nd parameter.
     *
     * @param array
     * @param d
     * @return
     */
    public static double[] multiply(double[] array, double d) {
        double[] product = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            product[i] = array[i] * d;
        }
        return product;
    }
}

Related

  1. multiply(double[] a, double v)
  2. multiply(double[] a, double[] b)
  3. multiply(double[] a, double[] b)
  4. multiply(double[] a, double[] b)
  5. multiply(double[] array, double multiplier)
  6. multiply(double[] source, double num)
  7. multiply(double[] values, int offset, int stride, int length, double multiplier)
  8. multiply(final double[] a, double b, final double[] dest, int n)
  9. multiply(final double[] inout, final double[] in)