# Finding total distance between a point and all points in a list?

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}]


but the suggested Table does not seem to return the correct output.

• There are a number of syntax errors in your code. The second line does not evaluated properly and the use of FindMinimum is incorrect as well. Please review your code for syntax errors first. Nov 6, 2017 at 16:54
• Try DistanceMatrix[Asubopt, A] Nov 6, 2017 at 16:54
• Thanks I added the space in the second line and DistanceMatrix[Asubopt,A] does contain the information I need but also computes all the distances to points in Asubopt as well. Nov 6, 2017 at 17:00
• I have used NMinimize as well. ClearAll["Global'*"]; n = 5 A = RandomVariate[NormalDistribution[5, 2], {n, 2}] dtotal[f_] := Total[Sqrt[Total[(Transpose[f] - {x, y})^2]]] minA = NMinimize[dtotal[A], {x, y}] Asub = Subsets[A, {1, n}] Asubdist = Map[dtotal, Subsets[A, {1, n}]] Asubopt = {x, y} /. NMinimize[#, {x, y}][[2]] & /@ Asubdist Nov 6, 2017 at 17:04
• Thanks Carl Total[DistanceMatrix[Asubopt,A],{2}] was what I was looking for! Nov 6, 2017 at 17:39

Total[DistanceMatrix[Asubopt,A],{2}]
`