Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Optimiser returns strange values
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!