Find all possible combinations of 2 vectores (spin) of a system with N atoms with pondered distance

1 visualización (últimos 30 días)
Hello!
I wanna take a tridimensional system of atoms, calculate the distance between them and all possible combinations of spin.
I want to take note that with the and being the magnetic moment of i and j repectivelly, which ones could take the values -1 and 1 and the values of 1's must be equal to the number of -1's. Thus, i want to take note of the value of and for each atom and for all different values of the sum.
Hope, you can help me fixing this problem. I leave what I have attached.
Thanks
  4 comentarios
Jan
Jan el 28 de Mzo. de 2019
Again: What is the wanted output? If you have 16 atoms, what does "tridimensional" mean?
Miguel Cardoso
Miguel Cardoso el 28 de Mzo. de 2019
3D(tridimentional) space
X Y Z
A= atom 1 [ 0.000000000 0.000000000 0.000000000
atom 2 0.000000000 0.000000000 2.700000048
atom 3 0.000000000 2.700000048 0.000000000
atom 4 0.000000000 2.700000048 2.700000048
atom 5 2.700000048 0.000000000 0.000000000
atom 6 2.700000048 0.000000000 2.700000048
atom 7 2.700000048 2.700000048 0.000000000
atom 8 2.700000048 2.700000048 2.700000048
atom 9 1.350000024 1.350000024 1.350000024
atom 10 1.350000024 1.350000024 4.050000191
atom 11 1.350000024 4.050000191 1.350000024
atom 12 1.350000024 4.050000191 4.050000191
atom 13 4.050000191 1.350000024 1.350000024
atom 14 4.050000191 1.350000024 4.050000191
atom 15 4.050000191 4.050000191 1.350000024
atom 16 4.050000191 4.050000191 4.050000191]
As I said before I want to calculate the distance between each atom, assign the values and 1 (spin) to each atom and calculate all possible combinations of these values.
The output should be
My main problem is how can I assign these values to each atom, guarantee that all combinations are executed and regist all possible combinations.
Thank you for spending your time trying to help me.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 28 de Mzo. de 2019
You have to bear in mind that most of us probably don't work in the same field as you do. Last time I had to worry about atom spin was some 20 years ago... So make sure to explain yourself clearly. Giving us code with syntax errors, or matrices that are not valid syntax does not help.
I want to calculate the distance between each atom,
I assume euclidean distance. That's trivially done, in just one line.
A=[ 0.000000000 0.000000000 0.000000000
0.000000000 0.000000000 2.700000048
0.000000000 2.700000048 0.000000000
0.000000000 2.700000048 2.700000048
2.700000048 0.000000000 0.000000000
2.700000048 0.000000000 2.700000048
2.700000048 2.700000048 0.000000000
2.700000048 2.700000048 2.700000048
1.350000024 1.350000024 1.350000024
1.350000024 1.350000024 4.050000191
1.350000024 4.050000191 1.350000024
1.350000024 4.050000191 4.050000191
4.050000191 1.350000024 1.350000024
4.050000191 1.350000024 4.050000191
4.050000191 4.050000191 1.350000024
4.050000191 4.050000191 4.050000191];
distance = sqrt(sum((permute(A, [1 3 2]) - permute(A, [3 1 2])) .^ 2, 3))
assign the values and 1 (spin) to each atom
That;s really not clear. Going by your +- diagram, I think you want to get all possible combinations of 8 atoms out of 16 (once you've chosen 8 positive spins, the others are negative). That's trivially done again however note that for 16 atoms, there are 12870 such combinations. For more atoms, it will easily get out of hands:
ncombs = nchoosek(size(A, 1), size(A, 1)/2); %number of combinations. If it's too large the following line will take forever and may even lock your computer
pospin = nchoosek(1:size(A, 1), size(A, 1)/2); %each row is a unique combination of 8 out 16 atoms
We can fill a matrix of -1 and +1 easily from there:
spin = -ones(size(pospin, 1), size(A, 1)); %fill with negative spin
spin(sub2ind(size(spin), repmat((1:size(spin, 1))', 1, size(pospin, 2)), pospin)) = 1; %fill selected atoms with positive spin
calculate all possible combinations of these values.
What values? Again, taking a guess based on your equation:
%using dimensional notation introduced in R2018b, here.
%in earlier versions, you'd have to call sum twice.
result = squeeze(sum(permute(spin, [3 2 1]) .* permute(spin, [2 3 1]) .* distance, [1 2]))
  3 comentarios
Guillaume
Guillaume el 28 de Mzo. de 2019
"sum all the distances between all atoms multiplied every single time by the spin of both for different configurations of spins"
This is exactly what the last line does:
result = squeeze(sum(permute(spin, [3 2 1]) .* permute(spin, [2 3 1]) .* distance, [1 2]))
at once for all spin combinations.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by