[Go to site: main page, start]

TOPICS
Search

Distance Matrix


For an ordered list X=(x_1,...,x_n) in a metric space with metric d, the distance matrix of X is the square matrix

 D_X=(d_(ij))=(d(x_i,x_j))_(i,j=1)^n.
(1)

It is symmetric, has zero diagonal and nonnegative entries, and its entries obey the triangle inequality d_(ij)<=d_(ik)+d_(kj). Conversely, any matrix with these properties and with d_(ij)=0 iff i=j defines a metric on its index set. A dissimilarity matrix need not satisfy all of these conditions.

Suppose x_1, ..., x_n are points in a Euclidean space. The matrix of their squared distances,

 Delta=(delta_(ij))=(||x_i-x_j||^2)_(i,j=1)^n,
(2)

is commonly called a squared Euclidean distance matrix, or sometimes simply a Euclidean distance matrix. Let 1 be the all-ones vector and define

J=I-1/n11^T
(3)
B=-1/2JDeltaJ.
(4)

Then B is the gram matrix of the points after translating their geometric centroid to the origin. A symmetric matrix Delta with zero diagonal is a squared Euclidean distance matrix iff B is positive semidefinite; equivalently, z^TDeltaz<=0 whenever z^T1=0 (Schoenberg 1935). The smallest Euclidean dimension in which the distances can be realized is rank(B) (Young and Householder 1938). If D=(d_(ij)) contains unsquared Euclidean distances, these criteria are applied to Delta=(d_(ij)^2).

If Delta is nonzero and the points have affine dimension r, then rank(Delta)<=r+2. More precisely, the rank is r+1 when the points lie on a hypersphere in their affine hull, and is r+2 otherwise (Gower 1985). Thus an affinely two-dimensional configuration gives a squared Euclidean distance matrix of rank at most 4, with rank 3 when the points lie on a circle.

Moreover, every nonzero squared Euclidean distance matrix has exactly one positive eigenvalue; all its other nonzero eigenvalues are negative.

A graph distance matrix is the distance matrix obtained from the graph distances among the vertices of a graph. Distance matrices also serve as input to multidimensional scaling and other methods that reconstruct or approximate point configurations from pairwise distances.

The distance matrix of a list of objects can be computed in the Wolfram Language using DistanceMatrix[{x1, ..., xn}], with the metric specified by the DistanceFunction option when needed. Choosing SquaredEuclideanDistance as the distance function produces Delta.


See also

Gram Matrix, Graph Distance Matrix, Metric Space, Multidimensional Scaling, Positive Semidefinite Matrix

Explore with Wolfram|Alpha

References

Alfonsi, J. "Four-Color Graphical Bioinformatics: The Machinery behind Phylogenetic Trees." Wolfram Community, Aug. 3, 2026. https://community.wolfram.com/groups/-/m/t/3773012.Dokmanić, I.; Parhizkar, R.; Ranieri, J.; and Vetterli, M. "Euclidean Distance Matrices: Essential Theory, Algorithms, and Applications." IEEE Signal Process. Mag. 32, 12-30, 2015. https://doi.org/10.1109/MSP.2015.2398954.Gower, J. C. "Properties of Euclidean and Non-Euclidean Distance Matrices." Lin. Alg. Appl. 67, 81-97, 1985. https://doi.org/10.1016/0024-3795(85)90187-9.Schoenberg, I. J. "Remarks to Maurice Fréchet's Article 'Sur la Définition Axiomatique d'une Classe d'Espaces Vectoriels Distanciés Applicables Vectoriellement sur l'Espace de Hilbert.' " Ann. Math. 36, 724-732, 1935. https://doi.org/10.2307/1968654.Young, G. and Householder, A. S. "Discussion of a Set of Points in Terms of Their Mutual Distances." Psychometrika 3, 19-22, 1938. https://doi.org/10.1007/BF02287916.

Referenced on Wolfram|Alpha

Distance Matrix

Cite this as:

Weisstein, Eric W. "Distance Matrix." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/DistanceMatrix.html

Subject classifications