![]() |
VOOZH | about |
Euclidean distance between two points in Euclidean space is the length of a line segment between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, therefore occasionally being called the Pythagorean distance. The Euclidean distance between the two vectors is given by
√Σ(vect1i - vect2i)2
where,
For example, we are given two vectors, vect1 as (1, 4, 3, 5) and vect2 as (2, 3, 2, 4). Their Euclidean distance is given by, √(1 - 2)2 + (4 - 3)2 + (3 - 2)2 + (5 - 4)2 which is equal to 2. Below is the implementation using two vectors of equal length:
Example 1:
Output:
👁 ImageExample 2:
Output:
👁 ImageIf the two vectors have unequal length then the compiler gives a warning message. Below is the implementation using two vectors having unequal length.
Example 3:
Output:
👁 ImageAs you can see in the output, the compiler gives us a warning since the length of vect1 is shorter than vect2.
Example 4:
Output:
👁 ImageAs you can see in the output, the compiler gives us a warning since the length of vect2 is shorter than vect1.