Problem with Genetic algorithm fitness function
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everybody I want to use genetic algorithm for optimizing 24 variable. The problem is this:
I implemented the code in this way:
if true
fitnessfunc=@fitness;
numberofvariables=24;
lb=zeros(1,24);
ub=[350 350 350 350 350 350 350 350 350 350 350 350 51 51 51 51 51 51 51 51 51 51 51 51];
[x,fval]=gamultiobj(@fitness,numberofvariables,[],[],[],[],lb,ub);
function C=fitness(Y)
x0=[3.2*10^5 10^10 0];
tspan=[0 350];
[t,y]=ode45(@(t,y) equations(t,y,Y),tspan,x0);
C=sum(y(:,2).^2)^2+y(350,2)^2+max(y(:,2))^2;
end
function dy = equations(t,y,glob)
%initial parameters value
dy = zeros(3,1);
s=1.3*10^4;
p=0.1245;
g=2.019*10^7;
m=3.422*10^(-10);
d=0.0412;
Mmax=50;
b=2.0*10^(-9);
a=0.18;
n=1.01*10^(-7);
Mth=10;
w=0.27;
o=0;
k=8.4*10^(-3);
time=glob(1:12);
u=glob(13:24);
delta=dirac(t-time)';
dose=u*delta;
%E=y1 , t=y2 , m=y3 landa=w
dy(1) = s+((p*y(1)*y(2))/(g+y(2)))-m*y(1)*y(2)-d*y(1)+o-k*((1-exp(-y(3)))*heaviside(y(3)-Mmax));
dy(2) = a*y(2)*(1-b*y(2))-n*y(1)*y(2)-k*((y(3)-Mth)*heaviside(y(3)-Mth));
dy(3) = dose-w*y(3);
end
end
I got the error. Is there any suggestion?
Thanks
댓글 수: 2
Alan Weiss
2015년 1월 14일
Please give us the MATLAB result, I mean the exact error message.
Alan Weiss
MATLAB mathematical toolbox documentation
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!