Rumus Euclidean Untuk mengHitung Jarak di Java

coding java untuk rumus euclidean distance
Berikut Prosesnya :
1. langkah pertama hitung selisih (array1 – array2)
2. lalu dipangkatkan 2 (Math.pow)
3. lalu dijumlahkan semuanya (sum = sum + datalama)
4. dan hasil dari penjumlahan di akar (Math.sqrt)

berikut code nya :

public static double calculateDistance(double[] array1, double[] array2)
{
double sum = 0.0;
for(int i=0;i<array1.length;i++) {
sum = sum + Math.pow((array1[i]-array2[i]),2.0);
}
return Math.sqrt(sum);
}

semoga membantu..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s