Here you can find the source of dotProduct(double[] x, double[] y)
public static double dotProduct(double[] x, double[] y)
//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; } }