Info

此问题已关闭。 请重新打开它进行编辑或回答。

Optimiser returns strange values

1 次查看(过去 30 天)
Hamzah Faraj
Hamzah Faraj 2020-7-20
关闭: MATLAB Answer Bot 2021-8-20
Hello,
I have been trying to minimse a function using the genatic algorithms (GA).
When I run the optimizer, it returns strange values.
It'd be very appreciated if someone can help me finding and solving the issue.
Note that the optimal value of V(t) should be either between ( 4 and 5) or (-1 and 0).
** Attached a file that explains the problem.
function z = costfunctiontest(x)
Vt = x;
A = [4/3, -4];
Vmax = 5; % Maximum temperature [°C]
Vhigh = 4; % High temperature [°C]
Vlow = 0; % Low temperature [°C]
Vmin = -1; % Minimum temperature [°C]
PiD = 30 ; % Discrete cost [£]
PiC = 10 ; % Continuous cost [£/h]
PiP = 50; % Penalty cost [£/h]
ContinuousTime = Vt/A(1);
TotalTime= Vt*((1/A(1))-(1/A(2)));
if ((Vt > Vhigh) & (Vt <= Vmax))
pvt = @(t) abs(Vt-Vhigh);
cost = (PiD + PiC*ContinuousTime + PiP*integral(pvt,0,TotalTime,'ArrayValued',true)) / TotalTime;
elseif ((Vt >= Vlow) & (Vt <= Vhigh))
cost = (PiD + PiC*ContinuousTime)/TotalTime;
else
pvt = @(t) abs(Vlow-Vt);
cost = (PiD + PiC*ContinuousTime + PiP*integral(pvt,0,TotalTime,'ArrayValued',true)) / TotalTime;
end
z=cost;
end
%% main code for minimising the fitness function using GA
ObjFcn = @costfunctiontest;
nvars = 1;
LB = [-1];
UB = [5];
[x,fval] = ga(ObjFcn,nvars,[],[],[],[],LB,UB)
  3 个评论
Matt J
Matt J 2020-7-20
Also, ga is a bit excessive for a 1-variable problem. It would be quicker just to use fminbnd over the 2 intervals of interest:
K>> [x,fval] = fminbnd(ObjFcn,-1,0)
x =
-6.6107e-05
fval =
-4.5380e+05
K>> [x,fval] = fminbnd(ObjFcn,4,5)
x =
4.0001
fval =
15.0032
Hamzah Faraj
Hamzah Faraj 2020-7-20
Thanks Matt J for your comments. In fact, the value of x in (4,5] should be equal to the value of x in [-1,0). In addition, fval cannot be a negative value as it’s a cost.
I really appreciate your help and the way you explained the difference between ga and Fminbnd.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by