Java Vector vectorCos(int[] d1, int[] d2)

Here you can find the source of vectorCos(int[] d1, int[] d2)

Description

vector Cos

License

Open Source License

Declaration

public static double vectorCos(int[] d1, int[] d2) throws IllegalArgumentException 

Method Source Code

//package com.java2s;

public class Main {

    public static double vectorCos(int[] d1, int[] d2) throws IllegalArgumentException {
        if (d1.length != d2.length)
            throw new IllegalArgumentException("length not equal");
        double l1 = 0.0, l2 = 0.0;
        long accumunate = 0;
        for (int i = 0; i < d1.length; i++) {
            l1 += d1[i] * d1[i];/*from   w  w w .j  a  v  a  2 s . c  om*/
            l2 += d2[i] * d2[i];
            accumunate += d1[i] * d2[i];
        }
        l1 = Math.sqrt(l1);
        l2 = Math.sqrt(l2);
        return (double) accumunate / (l1 * l2);
    }
}

Related

  1. vector2string(int[] vector)
  2. vector_dot(double[] vec1, double[] vec2)
  3. vector_norm(double[] vec)
  4. vector_sum(double[] v, double[] w)
  5. vectorAbsoluteValue(double X, double Y, double Z)
  6. vectorDiff(final double[] vecOne, final double[] vecTwo)
  7. vectorDir(int vert, int horiz)
  8. vectorDistance(double[] vec1, double[] vec2, double power)
  9. vectorIndexToUpperTriangularIndices(int numberOfRows, int index)