Java Array Dot Product dotProduct(double[] x, double[] y)

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

Description

dot Product

License

Open Source License

Declaration

public static double dotProduct(double[] x, double[] y) 

Method Source Code

//package com.java2s;
/**/*from   w ww .  j a  v a  2s.c o  m*/
 * Copyright 2004-2006 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 *
 * This file is part of MARY TTS.
 *
 * MARY TTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static double dotProduct(double[] x, double[] y) {
        assert x.length == y.length;

        double tmpSum = 0.0;
        for (int i = 0; i < x.length; i++)
            tmpSum += x[i] * y[i];

        return tmpSum;
    }

    public static double[][] dotProduct(double[][] x, double[][] y) {
        double[][] z = null;
        assert x.length == y.length;
        int numRows = x.length;
        int numCols = x[0].length;
        int i;
        for (i = 1; i < numRows; i++) {
            assert numCols == x[i].length;
            assert numCols == y[i].length;
        }

        if (x != null) {
            int j;
            z = new double[numRows][numCols];
            for (i = 0; i < numRows; i++) {
                for (j = 0; j < numCols; j++)
                    z[i][j] = x[i][j] * y[i][j];
            }
        }

        return z;
    }
}

Related

  1. dotProduct(double[] array, int[] indices, double[] values)
  2. dotProduct(double[] fv1, double[] fv2)
  3. dotProduct(double[] thisVector, double[] thatVector)
  4. dotProduct(double[] v, double[] u)
  5. dotProduct(double[] vector1, double[] vector2)
  6. dotProduct(final double[] a, final double[] b)
  7. dotProduct(final double[] anArray, final double[] anotherArray)
  8. dotProduct(final double[] v1, final double[] v2, int n)
  9. dotProduct(float x1, float y1, float x2, float y2)