Problem with Genetic algorithm fitness function
1 view (last 30 days)
Show older comments
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 Comments
Alan Weiss
on 14 Jan 2015
Please give us the MATLAB result, I mean the exact error message.
Alan Weiss
MATLAB mathematical toolbox documentation
Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!