I am looking for the total distance from each point in a list to all points in a another. Specifically from each point in Asubopt
to every point in A
.
ClearAll["Global'*"];
n = 5
A = RandomVariate[NormalDistribution[5, 2], {n, 2}]
dtotal[f_] := Total[Sqrt[Total[(Transpose[f] - {x, y})^2]]]
minA = FindMinimum[dtotal[A], {x}, {y}]
Asub = Subsets[A, {1, n}]
Asubdist = Map[dtotal, Subsets[A, {1, n}]]
Asubopt = {x, y} /. FindMinimum[#, {x}, {y}][[2]] & /@ Asubdist
Table[Outer[EuclideanDistance, {Asubopt[[i]]}, A, 1], {i, 1, n}]`
I read
but the suggested Table
does not seem to return the correct output.
FindMinimum
is incorrect as well. Please review your code for syntax errors first. $\endgroup$DistanceMatrix[Asubopt, A]
$\endgroup$