Here you can find the source of dotProduct(final double[] v1, final double[] v2, int n)
Parameter | Description |
---|---|
v1 | first vector of length <tt>n</tt> |
v2 | second vector of length <tt>n</tt> |
n | length of the vectors |
public static double dotProduct(final double[] v1, final double[] v2, int n)
//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; } }