Here you can find the source of euclideanDist(final double[] vec1, final double[] vec2, int n)
Parameter | Description |
---|---|
vec1 | a real vector |
vec2 | another real vector |
n | length of two vectors |
public static double euclideanDist(final double[] vec1, final double[] vec2, int n)
//package com.java2s; //License from project: Open Source License public class Main { /**//w w w. j av a 2 s.c o m * Compute the euclidean distance between 2 vectors. * Preconditions : vec1.length == vec2.length == n * @param vec1 a real vector * @param vec2 another real vector * @param n length of two vectors * @return the euclidean distance between vec1 and vec2 */ public static double euclideanDist(final double[] vec1, final double[] vec2, int n) { assert vec1 != null; assert vec2 != null; assert vec1.length == n; assert vec2.length == n; double dist = 0; for (int i = 0; i < n; i++) { dist += Math.pow(vec1[i] - vec2[i], 2); } return Math.sqrt(dist); } }