You are on page 1of 4

Euclidean Distance (P.

69)
z Euclidean distance is the usual method of computing
distance that you are used to

z In 1 dimension it is the absolute value

z In 2 dimensions it is the Pythagorean Theorem

z In more than 2 dimensions it is just a generalization of


the Pythagorean Theorem
n 2
dist = ∑ ( pk − qk )
k =1

z In R, the function dist() computes distances 41


In class exercise #49:
Compute the distance between the points c(2,2) and
c(5,7) by hand and verify that the function dist in R
gives the same value.

42
In class exercise #49:
Compute the distance between the points c(2,2) and
c(5,7) by hand and verify that the function dist in R
gives the same value.

Solution:

x1<-c(2,2)
x2<-c(5,7)

data<-matrix(c(x1,x2),nrow=2,byrow=T)

dist(data)

43
In class exercise #50:
Compute the distance between the points c(2,2,3) and
c(5,7,10) by hand and verify that the function dist in R
gives the same value.

44

You might also like