Learn R Programming

gor (version 2.0)

compute_distance_matrix: \(p\)-distance matrix computation

Description

It computes the distance matrix of a set of \(n\) two-dimensional points given by a \(n\times 2\) matrix using the distance-\(p\) with \(p=2\) by default.

Usage

compute_distance_matrix(z, p = 2)

Value

The distance-\(p\) of the points.

Arguments

z

A \(n\times 2\) matrix with the two-dimensional points

p

The \(p\) parameter of the distance-\(p\). It defaults to 2.

Author

Cesar Asensio

Details

Given a set of \(n\) points \(\{z_j\}_{j=1,...,n}\), the distance matrix is a \(n\times n\) symmetric matrix with matrix elements $$d_{ij} = d(z_i,z_j)$$ computed using the distance-\(p\) given by $$d_p(x,y) = \left(\sum_i (x_i-y_i)^p\right)^{\frac{1}{p}}$$.

See Also

compute_p_distance computes the distance-\(p\), compute_tour_distance computes tour distances. A distance matrix can also be computed using dist.

Examples

Run this code
set.seed(1)
n <- 25
z <- cbind(runif(n,min=1,max=10),runif(n,min=1,max=10))
d <- compute_distance_matrix(z)

Run the code above in your browser using DataLab