Here you can find the source of cos(double[] v1, double[] v2)
public static double cos(double[] v1, double[] v2)
//package com.java2s; //License from project: Apache License public class Main { public static double cos(double[] v1, double[] v2) { double s = 0; s = multiple(v1, v2);/*w w w .j av a 2 s. c o m*/ double a = Math.pow(multiple(v1, v1) * multiple(v2, v2), 0.5); return s / a; } public static double multiple(double[] v1, double[] v2) { double v = 0; for (int i = 0; i < v1.length; i++) { v = v + v1[i] * v2[i]; } return v; } }