Rudolf Adamkovič Personal site


Euclidean distance

a.k.a.

Define

… as the length of the vector difference

\[\begin{equation*}
  \| \vec{u} - \vec{v} \|.
\end{equation*}
\]

Imagine

… in the real plane \(\mathbb{R}^2\):

  1. Draw \(\vec{u}, \vec{v}\) as points \(P\) and \(Q\).
  2. Measure the length of the line segment \(\overline{PQ}\).

Closed form

… is

\[\begin{equation*}
  \| \vec{u} - \vec{v} \|
  = \left\|
  \begin{pmatrix} u_1 \\ \vdots \\ u_m \end{pmatrix}
  -
  \begin{pmatrix} v_1 \\ \vdots \\ v_m \end{pmatrix}
  \right\|
  = \sqrt{{(u_1 - v_1)}^2 + \cdots + {(u_m - v_m)}^2}.
\end{equation*}
\]

Derive

… the closed form as

\[\begin{align*}
  \| \vec{u} - \vec{v} \|
  \tag{1}
  & = \left\|
  \begin{pmatrix} u_1 \\ \vdots \\ u_m \end{pmatrix}
  -
  \begin{pmatrix} v_1 \\ \vdots \\ v_m \end{pmatrix}
  \right\|
  \\[1ex]
  \tag{2}
  & = \sqrt{(\vec{u} - \vec{v}) \cdot (\vec{u} - \vec{v})}
  \\[1ex]
  \tag{3}
  & = \sqrt{\sum_{i = 1}^{m} (u_i - v_i) (u_i - v_i) }
  \\[1ex]
  \tag{4}
  & = \sqrt{\sum_{i = 1}^{m} {(u_i - v_i)}^2 }
  \\[1ex]
  \tag{5}
  & = \sqrt{{(u_1 - v_1)}^2 + \cdots + {(u_m - v_m)}^2}
\end{align*}
\]

with

  1. by vector,
  2. by vector length,
  3. by dot product,
  4. by exponentiation, and
  5. by summation.

Derive again

… the closed form as

\[\begin{align*}
  \| \vec{u} - \vec{v} \|
  \tag{1}
  & = \left\|
  \begin{pmatrix} u_1 \\ \vdots \\ u_m \end{pmatrix}
  -
  \begin{pmatrix} v_1 \\ \vdots \\ v_m \end{pmatrix}
  \right\|
  \\[1ex]
  \tag{2}
  & = \sqrt{(\vec{u} - \vec{v}) \cdot (\vec{u} - \vec{v})}
  \\[1ex]
  \tag{3}
  & = \sqrt{{(\vec{u} - \vec{v})}^\mathsf{T} (\vec{u} - \vec{v})}
  \\[1ex]
  \tag{4}
  & = \sqrt{
    \begin{pmatrix}
      \vphantom{\bigg(}
      u_1 - v_1 & \cdots & u_m - v_m
    \end{pmatrix}
    \begin{pmatrix}
      u_1 - v_1 \\ \vdots \\ u_m - v_m
    \end{pmatrix}
  }
  \\[1ex]
  \tag{5}
  & = \sqrt{(u_1 - v_1) (u_1 - v_1) + \cdots + (u_m - v_m) (u_m - v_m)}
  \\[1ex]
  \tag{6}
  & = \sqrt{{(u_1 - v_1)}^2 + \cdots + {(u_m - v_m)}^2}
\end{align*}
\]

with

  1. by vector,
  2. by vector length,
  3. by the dot product in terms of the matrix transpose,
  4. by the matrix transpose,
  5. by matrix multiplication, and
  6. by exponentiation.

Denote

… as shown above, or

\[\begin{equation*}
  \| \vec{u} - \vec{v} \|
  = d(\vec{u}, \vec{v})
  = \operatorname{dist}(\vec{u}, \vec{v}).
\end{equation*}
\]

Implement

… in Scheme as



© 2024 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.