Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I'm Trying to write minimization function from this function,
(4-2.1*x1^2+x1^4/3)*x1^2+x1*x2+(-4+4*x2^2)*x2^2
where,
-10 <= x1 <= 10 and -10 <= x2 <= 10.
this what I'm writing, is this right?
min = -10;
max = 10;
x1 = min+max*rand();
x2 = min+max*rand();
T = 1.0;
Tmin = 0.0000001;
refresh = 0.9;
finalMin = (4-2.1*x1^2+x1^4/3)*x1^2+x1*x2+(-4+4*x2^2)*x2^2;
finalCoordinate=[x1,x2];
while(T>Tmin)
i=0;
while(i<=300)
x1= min+max*rand(1,1);
x2= min+max*rand(1,1);
newMin = (4-2.1*x1^2+x1^4/3)*x1^2+x1*x2+(-4+4*x2^2)*x2^2;
delta1 = finalMin-newMin;
if(newMin < finalMin)
finalMin=newMin;
finalCoordinate=[x1,x2];
elseif(2.71828^(delta/T))>(0+(rand(1)*1))
finalCoordinate=[x1,x2];
end;
i=i+1;
end;
T = T*refresh;
end;
But why, at
elseif(2.71828^(delta/T))>(0+(rand(1)*1))
Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
And how to obtain 100% accuracy from that coordinate?
0 Kommentare
Antworten (1)
Walter Roberson
am 22 Sep. 2017
Your code does not define delta so you are getting whatever value happened to be laying around, which happened to be a vector or array.
Note: use exp(x) instead of 2.718^(x)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Simulated Annealing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!