Java Array Dot Product dotProduct(float[] v1, float[] v2)

Here you can find the source of dotProduct(float[] v1, float[] v2)

Description

Calculate the dot-product result of two vectors.

License

Open Source License

Parameter

Parameter Description

Return

dot product

Declaration


public static float dotProduct(float[] v1, float[] v2) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww  w  .j  a  v  a  2  s  .c  o  m
     * Calculate the dot-product result of two vectors.
     *
     * @param v1, vector 1
     * @param v2, vector 2
     * @return dot product
     */

    public static float dotProduct(float[] v1, float[] v2) {
        assert v1.length == v2.length;
        float result = 0;
        for (int i = 0; i < v1.length; i++) {
            result += v1[i] * v2[i];
        }
        return result;
    }
}

Related

  1. dotProduct(final double[] a, final double[] b)
  2. dotProduct(final double[] anArray, final double[] anotherArray)
  3. dotProduct(final double[] v1, final double[] v2, int n)
  4. dotProduct(float x1, float y1, float x2, float y2)
  5. dotProduct(float[] p, int a, int b, int c)
  6. dotProduct(float[] vector1, float[] vector2)
  7. dotProduct(int[] xs, int[] ys)