Created
December 25, 2011 14:11
-
-
Save paddya/1519330 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @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