Here you can find the source of distance(final double[] a, final double[] b)
Parameter | Description |
---|---|
a | a parameter |
b | a parameter |
public static double distance(final double[] a, final double[] b)
//package com.java2s; public class Main { /**//from w w w . ja va 2s. c o m * get the length of (a - b). * * @param a * @param b */ public static double distance(final double[] a, final double[] b) { return Math.sqrt(squareDistance(a, b)); } /** * get the squared length of (a - b). * * @param a * @param b */ public static double squareDistance(final double[] a, final double[] b) { assert rows(a) == rows(b); final int rows = rows(a); double squ_len = 0.0; for (int i = 0; i < rows; ++i) squ_len += (a[i] - b[i]) * (a[i] - b[i]); return squ_len; } public static int rows(final double[] a) { return a.length; } public static int rows(final double[][] A) { return A.length; } }