Optimiser returns strange values
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comments
Note that the optimal solution shouls be a value between ( 4 and 5) or (-1 and 0).
I don't see why the solution couldn't fall anywhere between the LB and UB that you've supplied. However, here are the results that I get.
x =
-4.4789e-05
fval =
-6.6980e+05
Since x falls within the bounds that you mention, I see nothing confounding about the result.
Matt J
on 20 Jul 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
on 20 Jul 2020
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!