minkowski
Syntax
minkowski(X, Y, p, [weights])
Details
Compute the Minkowski distance between two one-dimensional numeric vectors (X and Y). The distance is defined as follows:
Parameters
X: A one-dimensional numeric vector.
Y: A one-dimensional numeric vector.
p: An integer scalar with p ≥ 1, used to specify the type of distance:
- p = 1: Manhattan distance
- p = 2: Euclidean distance
weights (optional): A one-dimensional non-negative numeric vector specifying the weights of each element in X and Y. The default value of each element is 1.
Note:
X, Y, and weights must have the same length.
Returns
A scalar of type DOUBLE.
Examples
Assume two one-dimensional vectors:
X = [1, 2]
Y = [4, 6]
- When p = 1, compute the Manhattan
distance:
minkowski(X,Y,p) // Output: 7
- When p = 2, compute the Euclidean
distance:
minkowski(X,Y,p) // Output:5
