Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Optimiser returns strange values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Matt J
le 20 Juil 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
Réponses (0)
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!