Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Walter Roberson
2017 年 9 月 22 日
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 件のコメント
参考
カテゴリ
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!