Java Array Dot Product dotProduct(final double[] v1, final double[] v2, int n)

Here you can find the source of dotProduct(final double[] v1, final double[] v2, int n)

Description

Computes the dotproduct of the given vectors.

License

Open Source License

Parameter

Parameter Description
v1 first vector of length <tt>n</tt>
v2 second vector of length <tt>n</tt>
n length of the vectors

Return

dot product of v1 and v2

Declaration

public static double dotProduct(final double[] v1, final double[] v2, int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  ww  w. ja va  2 s . c  o  m*/
     * Computes the dotproduct {@code <v1,v2>} of the given vectors.
     * 
     * @param v1
     *            first vector of length <tt>n</tt>
     * @param v2
     *            second vector of length <tt>n</tt>
     * @param n
     *            length of the vectors
     * @return dot product of <tt>v1</tt> and <tt>v2</tt>
     */
    public static double dotProduct(final double[] v1, final double[] v2, int n) {
        assert v1 != null;
        assert v2 != null;
        assert v1.length >= n;
        assert v2.length >= n;

        double dp = 0;
        for (int i = 0; i < n; i++) {
            dp += v1[i] * v2[i];
        }
        return dp;
    }
}

Related

  1. dotProduct(double[] v, double[] u)
  2. dotProduct(double[] vector1, double[] vector2)
  3. dotProduct(double[] x, double[] y)
  4. dotProduct(final double[] a, final double[] b)
  5. dotProduct(final double[] anArray, final double[] anotherArray)
  6. dotProduct(float x1, float y1, float x2, float y2)
  7. dotProduct(float[] p, int a, int b, int c)
  8. dotProduct(float[] v1, float[] v2)
  9. dotProduct(float[] vector1, float[] vector2)