Java Array Dot Product dotProduct(double[] a, double[] b)

Here you can find the source of dotProduct(double[] a, double[] b)

Description

Returns the dot product between two vectors

License

Open Source License

Parameter

Parameter Description
a first vector
b second vector

Exception

Parameter Description
IllegalArgumentException if the two vector don't have the same length

Return

the dot product

Declaration

public static float dotProduct(double[] a, double[] b) 

Method Source Code

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

public class Main {
    /**//from   w w w. jav a2  s .c o  m
     * Returns the dot product between two vectors
     *
     * @param a first vector
     * @param b second vector
     * @return the dot product
     * @throws IllegalArgumentException if the two vector don't have the same length
     */
    public static float dotProduct(double[] a, double[] b) {
        if (a.length != b.length) {
            throw new IllegalArgumentException(
                    "Error computing dotProduct in Utilities.dotProduct: arrays should have the same length");
        }
        float sp = 0;
        for (int i = 0; i < a.length; i++) {
            sp += a[i] * b[i];
        }

        return sp;
    }
}

Related

  1. dotProd(float[] a, float[] b)
  2. dotProduct(double x1, double y1, double x2, double y2)
  3. dotProduct(double x1, double y1, double x2, double y2, double x3, double y3)
  4. dotProduct(double[] a, double[] b)
  5. dotProduct(double[] a, double[] b)
  6. dotProduct(Double[] a, Double[] b)
  7. dotProduct(double[] array, int[] indices, double[] values)
  8. dotProduct(double[] fv1, double[] fv2)
  9. dotProduct(double[] thisVector, double[] thatVector)