Java Array Multiply multiply(final double[] x, final double[] y)

Here you can find the source of multiply(final double[] x, final double[] y)

Description

Returns newly allocated array which is the result of termwise multiplication of the input arrays

License

Open Source License

Parameter

Parameter Description
first a parameter
second a parameter

Exception

Parameter Description
ArrayIndexOutOfBoundsException if the arrays are of unequal length

Return

Side Effects: Allocation of the returned array

Declaration

final public static double[] multiply(final double[] x, final double[] y) 

Method Source Code

//package com.java2s;
/*//from  ww w. java2s.  c  o m
 * ====================================================
 * Copyright (C) 2013 by Idylwood Technologies, LLC. All rights reserved.
 *
 * Developed at Idylwood Technologies, LLC.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * The License should have been distributed to you with the source tree.
 * If not, it can be found at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Charles Cooper
 * Date: 2013
 * ====================================================
 */

public class Main {
    /**
     * Returns newly allocated array which is the result
     * of termwise multiplication of the input arrays
     * @param first
     * @param second
     * @throws ArrayIndexOutOfBoundsException if the arrays are of unequal length
     * @return
     * Side Effects: Allocation of the returned array
     */
    final public static double[] multiply(final double[] x, final double[] y) {
        final int len = x.length;
        if (len != y.length)
            throw new ArrayIndexOutOfBoundsException("Tried to multiply two vectors of unequal length!");
        final double ret[] = new double[len];
        for (int i = 0; i < len; i++)
            ret[i] = x[i] * y[i];
        return ret;
    }
}

Related

  1. multiply(double[] values, int offset, int stride, int length, double multiplier)
  2. multiply(final double[] a, double b, final double[] dest, int n)
  3. multiply(final double[] inout, final double[] in)
  4. multiply(final double[] lhs, final double[] rhs)
  5. multiply(final double[] v1, final double[] v2)
  6. multiply(final float[] complexA, final float[] complexB, final boolean overwriteA)
  7. multiply(final int[] numbers)
  8. multiply(float[] array, float factor)
  9. multiply(float[] array, int multiplier)