Classical scaling
The task of MDS is to find the original Euclidean coordinates from a given distance matrix D.
The Euclidean distance between the
and
is given by

B is the inner-product of dimensional-reduced coordinates. The general
term of B is given by

We can derive B from D:

For convenient computation, we centre the coordinate matrix X, which implies that
(the sum of the column of B is zero), because the inner product matrix is symmetric, so 
Summing over i, we obtain
(59) because 

Summing over j, we obtain
(60)

Summing over equation(60), we obtain


We already know that
;
so 
Define the matrix
as
and observe that:

The inner product matrix
can be expressed as

where
is the
matrix of coordinates.
The rank of
is then

is symmetric, positive definite, of rank p and has p non-zero eigenvalues.
B can now be written as 
where
, the diagonal matrix of the eigenvalues of B, and
, the matrix of corresponding eigenvectors.
Hence the coordinate matrix X containing the point configuration in
is given by 
Pseudocode
The algorithm for recovering coordinates from distances
between pairs of points is as follows:
- Form matrix

- Form matrix $latex \pmb{B}=\pmb{HAH}$, where H is the cantering matrix

- Find the spectral decomposition of B, and V is the matrix of corresponding eigenvectors.
- If the points were originally in a p-dimensional space, the first p eigenvalues of K are nonzero and the remaining n-p are zero. Discard these from
(rename as
), and discard the corresponding eigenvalues from V (rename as
).
- Find
, and then the coordinates of the points are given by the rows of X.