Accept a solution in a simple program
2 次查看(过去 30 天)
显示 更早的评论
Hello, i am not quite sure about the result i got, whether to ACCEPT or NOT ACCEPT with probability , i think its a metropolis algorithm or simulated annealing Algorithm, it says :
-
%M = number of moves to attempt
%T=current temperature
%for m = 1 to M{
%Generate a random move e.g, move a particle
%Evaluate the change in energy, Delta E
%if (Delta E < 0)
%/*downhill move : accept it*/
%accept this move and update configuration
%}
%else{
%/*uphill move : accept maybe*/
%accept this move with probability of P = e^(-Delta E / T)
%update configuration if accepted
%}
%}/*end for loop*/
------------- matlab code start from here -----------------------
clear all;clc
M= 20;%M = number of moves to attempt
T = 25;%T=current temperature
e = exp(1);
for m = 1:M
randmove = randi(60,1);
DeltaE=randmove-T;
if DeltaE<0
moveaccepted = DeltaE;
else
prob = e^(-DeltaE/T);
configg = [DeltaE,(1-prob)*100];%100% acceptance ,(1-prob)*100
end
end
configg
------------- end matlab code start from here -----------------------
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulated Annealing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!