Reputation: 83
I want to write a function in Matlab and call it repeatedly. this is my code:
function T=FirstTemperature()
clc
T=0.8;
randVariable=10*rand(1,2);
ErandVariable=Objectivef(randVariable(1),randVariable(2));
present=randVariable;
Epresent=ErandVariable;
DEpositive=0;
positive=0;%for counting DeltaEpositive
for i=1:10
randVariable=10*rand(1,2);
ErandVariable =Objectivef(randVariable(1),randVariable(2));
DE=(ErandVariable-Epresent);
if(DE<0)
present=randVariable;
Epresent=ErandVariable;
% disp('i move there')
else
DEpositive=DE+DEpositive;
positive=positive+1;%for counting
P=exp(- (DE)/ (2.038*T));
a=rand(1);
if(P>a)
present=randVariable;
Epresent=ErandVariable;
%disp('with A probability i accepted')
end
end
end
x0=0.9;
averag=DEpositive/positive;%average of deltapositive
T=averag/log(x0);
end
and I call this function repeatedly in a script file , in this way:
for k=1:10
disp('Hello')
T=FirstTemperature()
end
I want to display "Hello" for being aware of how does it run. this is the output:
Hello
T =
-135.9965
>>
So,my code runs just one time instead of repeatting 10 time,What can I do ?
Upvotes: 0
Views: 139