I want to create a list of (n-dimension, average of points) with 10,000 points per n-dimension.
I can't figure out how to take the distance of consecutive points. Say in 2-dimensions, there are 3 points, how can I create a distance function that will calculate the distance between point 1 and 2, point 2 and 3, and point 3 and 1?
I have tried writing a definition with the distance formula, I have also tried subtracting the points and using dot product. I am not getting the correct results, and also get an error for 1 dimension.
Below is my attempt for 3-dimensions, with 3 points.
Thank you in advance for your help!
List of 3 n -dimensional points
ndim[n_] := ndim[n] = Table[ Table[Random[Real, {0, 1}], {i, 1, n}], {3}]
ndim[1]
> {{0.101636}, {0.552763}, {0.746901}}
ndim[2]
>{{0.487501, 0.793056}, {0.0315906, 0.406843}, {0.539288, 0.479365}}
ndim[3]
>{{0.137648, 0.0813221, 0.272689}, {0.196472, 0.76574, 0.145624}, {0.730333, 0.690326, 0.575955}}
Consecutive distance square between 2 points for 3 data points per n-dimension:
dsqr[n_] := Table[(ndim[n][[i, 1]] - ndim[n][[i, 2]])^2, {i, 1, Length[ndim[n]]}]
dsqr[1]
> During evaluation of In[254]:= Part::partw: Part 2 of {0.101636} does not exist.
> During evaluation of In[254]:= Part::partw: Part 2 of {0.552763} does not exist.
> During evaluation of In[254]:= Part::partw: Part 2 of {0.746901} does not exist.
> During evaluation of In[254]:= General::stop: Further output of Part::partw will be suppressed during this calculation.
> {(0.101636 - {{0.101636}, {0.552763}, {0.746901}}[[1, 2]])^2, (0.552763 - {{0.101636}, {0.552763}, {0.746901}}[[2, 2]])^2, (0.746901 - {{0.101636}, {0.552763}, {0.746901}}[[3, 2]])^2}
dsqr[2]
> {0.0933638, 0.140814, 0.00359085}
dsqr[3]
> {0.00317264, 0.324066, 0.0016005}
Average distance for 3 data points for n-dimension:
davg[n_] := Plus @@ Sqrt[dsqr[n]]/Length[dsqr[n]];
davg[2]
> 0.24691
davg[3]
>0.221867
Table with ordered pair (n-dimension, Dave) for 3 data points:
orderpairs[n_] := Table[{i, davg[n]}, {i, 1, n}];
orderpairs[3]
> {{1, 0.221867}, {2, 0.221867}, {3, 0.221867}}
EuclideanDistance @@@ Partition[pts, 2, 1, 1]
for this. $\endgroup$Mean[EuclideanDistance @@@ Partition[dsqr[n], 2, 1, 1]]
? $\endgroup$