Need help with calculating the minimum potential energy of two particles.
Mostrar comentarios más antiguos
Hello, I am attempting to find the minimum potential between particles. One of the particles is fixed at the point (0,0) and the other particle is allowed to move freely and I have set that particle at an arbitrary point, in this case (5,5). I am trying to use the Monte Carlo method of finding a minimum potential energy between the two particles. The free particle is supposed to slightly move around and slightly vary its angle theta and these new values are then used to calculate the new potential energy of the system. If the potential energy of the system is lower then these new values are saved and the calculation is repeated with the new values. However, if the potential energy increases then these new values are discarded and a new calculation is carried out so far. Here is what I have so far,
%Variable declaration
epsilon = (8.85*10^-12); %permittivity of free space
constant = 1/(4*pi*epsilon); %form of the coulomb constant
%position initialization of the fixed particle
particle.x = 0;
particle.y = 0;
dipole.angle.fixed.particle = pi/2;
%position initialization of the free particle
particle.x1 = 5; %set at arbitrary position
particle.y1 = 5; %set at arbitrary position
particle.theta = pi/6
%calculation of initial energy
initial.potential.energy = ((-1)*constant*1*1*(cos(dipole.angle.fixed.particle - particle.theta)))./(((particle.x1 - particle.x).^2 + (particle.y1 - particle.y).^2).^(3/2))
for i = 1:100
deltaX = particle.x1 + 0.1*randn(1) - 0.1;
deltaY = particle.y1 + 0.1*randn(1) - 0.1;
theta = particle.theta + randn(1);
potential.energy(i) = ((-1)*constant*1*1*(cos(dipole.angle.fixed.particle - particle.theta)))./(((deltaX - particle.x).^2 + (deltaY - particle.y).^2).^(3/2))
if (potential.energy(i) < initial.potential.energy)
particle.x1 = deltaX;
particle.y1 = deltaY;
particle.theta = theta;
initial.potential.energy = potential.energy
end
end
I believe my problem is that the if condition in my for loop isn't activating and therefore the values that lead to a lower potential energy aren't being saved. Instead the program is doing the calculation with whatever values it wants. I am unsure how to fix this error or where the error in my code is and any help at all would be appreciated to fix this issue and to get this program actually working.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Particle & Nuclear Physics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!