Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Optimiser returns strange values

1 visualizzazione (ultimi 30 giorni)
Hamzah Faraj
Hamzah Faraj il 20 Lug 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commenti
Matt J
Matt J il 20 Lug 2020
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 il 20 Lug 2020
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.

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by