Here you can find the source of dotProduct(double[] a, double[] b)
Parameter | Description |
---|---|
a | first vector |
b | second vector |
Parameter | Description |
---|---|
IllegalArgumentException | if the two vector don't have the same length |
public static float dotProduct(double[] a, double[] b)
//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; } }