Java Vector Product vectorDotProduct(double[] v1, double[] v2)

Here you can find the source of vectorDotProduct(double[] v1, double[] v2)

Description

vector Dot Product

License

Open Source License

Declaration

public static double vectorDotProduct(double[] v1, double[] v2) 

Method Source Code

//package com.java2s;
/*/*from   w  w w.j a va2s.  c o m*/
 * Created on 12.12.2004
 * 
 * COPYRIGHT NOTICE
 * 
 * Copyright (C) 2005 DFKI GmbH, Germany
 * Developed by Benedikt Fries, Matthias Klusch
 * 
 * The code is free for non-commercial use only.
 * You can redistribute it and/or modify it under the terms
 * of the Mozilla Public License version 1.1  as
 * published by the Mozilla Foundation at
 * http://www.mozilla.org/MPL/MPL-1.1.txt
 */

public class Main {
    public static double vectorDotProduct(double[] v1, double[] v2) {
        if (v1.length != v2.length)
            return 0;
        double sum = 0;
        for (int i = 0; i < v1.length; i++)
            sum += v1[i] * v2[i];
        return sum;
    }

    public static double vectorDotProduct(int[] v1, int[] v2) {
        if (v1.length != v2.length)
            return 0;
        double sum = 0;
        for (int i = 0; i < v1.length; i++)
            sum += v1[i] * v2[i];
        return sum;
    }
}

Related

  1. vector_product(double[] v, double[] w)
  2. vectorDotProduct(double X1, double Y1, double Z1, double X2, double Y2, double Z2)
  3. vectorProduct(double[] x, boolean isColumnVectorX, double[] y, boolean isColumnVectorY)
  4. vectorProduct(float[] x, float[] y)