Skip to content

Instantly share code, notes, and snippets.

@paddya
Created December 25, 2011 14:11
Show Gist options
  • Save paddya/1519330 to your computer and use it in GitHub Desktop.
Save paddya/1519330 to your computer and use it in GitHub Desktop.
/**
*
* @author Patrick Bisenius
*/
public class MathUtil {
public static double scalarProduct(double[] v1, double[] v2) {
double scalarProduct = 0;
for(int i = 0; i < v1.length; i++) {
scalarProduct += v1[i] * v2[i];
}
return scalarProduct;
}
public static double cosine(double[] v1, double[] v2) {
return scalarProduct(v1, v2) / (Math.sqrt((scalarProduct(v1, v1) * scalarProduct(v2, v2))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment