I see that you are at least using the answers to your previous questions to improve your code, but I do think you need to spend a bit more time with the documentation so that you better understand what you are doing. It really doesn't make people keen to help when you come back with the same problem and ask for help at every step.
Once you clean up the code with semicolons, you don't get errors any more, but the result is something like a 100-length vector where each element looks like:
1/125 A[0, 0, 0] + 1/125 A[0, 0, 1] + 1/125 A[0, 0, 2] +
1/125 A[0, 0, 3] + 1/125 A[0, 0, 4] + 1/125 A[0, 1, 0] +
1/125 A[0, 1, 1] + 1/125 A[0, 1, 2] + 1/125 A[0, 1, 3] +
1/125 A[0, 1, 4] + 1/125 A[0, 2, 0] + <<103>> + 1/125 A[4, 2, 4] +
1/125 A[4, 3, 0] + 1/125 A[4, 3, 1] + 1/125 A[4, 3, 2] +
1/125 A[4, 3, 3] + 1/125 A[4, 3, 4] + 1/125 A[4, 4, 0] +
1/125 A[4, 4, 1] + 1/125 A[4, 4, 2] + 1/125 A[4, 4, 3] +
1/125 A[4, 4, 4]
I'm sure that's not what you intended. The use of %
inside the Table
(or Module
) seems unnecessary and I think it is part of the problem.
If you compress the last three lines inside your Table
to
Total[N[Map[distanceBetween, c]] ]/d
you will get numerical data of the kind I think you are looking for.
There are some other problems with your code, e.g. the unnecessary manual calculation of mean instead of using Mean
(so you can remove the other %
). I also think that calculating the energies inside the Table
means that if you select the same element in more than one of your RandomSample
s, it will have a different energy each time. I am sure this is not what you intend. The problem here is not with your understanding of Mathematica, it is with your understanding of what you are trying to do. Try writing out step by step in pseudocode or math first, to test if you have made a conceptual error in your implementation.
I'll also point out that if you hadn't given the elements of Xarray
a Head
of A
using A @@@
, you wouldn't need the List @@
code further down in the distance between function.
In any case if you redefine your distanceBetween
function like this, you won't need to keep inefficiently redefining it in each iteration of the Table
.
distanceBetween[lst_, {n_, m_}] := Norm[List @@ lst[[n, 1]] - List @@ lst[[m, 1]]]
Alternatively, leave the elements of Xarray
as lists not A[1,2,3]
and so on, and you can just use the EuclideanDistance
function instead of recoding it yourself.
Table
command you used. You should not use symbols that start with a capital letter such as Xarray or A, M as those might shadow MMa symbols. $\endgroup$Length@Xarray;
doesn't seem to do anything, is there a use for it ? And what is the purpose ofA
, it seems redundant? $\endgroup$Table
command is incomplete. Also you are assigning repeatedly a list to a single variable. do you meanm = Table[RandomSample[Xarray,7],{100}]
or so? $\endgroup$