Help to Run Genetic Algorithm
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I am trying run a ga which were given in article that I am read, but the following error appears and I don't know how fix it and I will show the steps lower and I attached the page in this ask.
Optimization running.
Error running optimization.
Undefined function 'b' for input arguments of type 'double'.
Steps:
1 .Write a function to minimize the weight wich is given by:
function y = min_weight(x)
y = ((3.14*p)./4000).*(b*m.^2 *z(1).^2 * (1+a.^2))-((D(i).^2 - d(o).^2)*.(l-b(w))-(n*d(p).^2 .* b(w))-((d(1).^2 + d(2).^2).*b));
2. Write a function with constraints:
c = [b(1)-F(s); b(2)-(F(s)./F(p)); b(3)-d(1).^3; b(4)-d(2).^3; ((1+a).*m.*z(1)./2)-b(5)];
Ceq = [];
3rd, 4th and 5th steps I am ok.
6. I put the lower and upper bounds as [20;15;30;18;1] and [20;15;30;18;1] respectively;
However I tryed make the other steps and the message said before appeared.So I am also leaving the picture of the optimization tool as the attachment for help you to help me.
I appreciate your attention
Rafael Zanetti
5 个评论
Stephan
2020-11-25
I think you missed to build in this informations:

So far the code looks like
options = optimoptions('ga');
% options = optimoptions(options,'PopulationType', 'custom');
options = optimoptions(options,'Display', 'off');
nvars = 5;
lb = [20,15,30,18,1];
ub = [35,32,50,25,4];
[x,fval,exitflag,output,population,score] = ...
ga(@min_weight,nvars,[],[],[],[],lb,ub,@gear_constraint,[],options);
function [c,ceq] = gear_constraint(x)
b = x(1);
d1 = x(2);
d2 = x(3);
Z1 = x(4);
m = x(5);
c = [b(1)-F(s); b(2)-(F(s)./F(p)); b(3)-d1.^3; b(4)-d2.^3; ((1+a).*m.*Z1./2)-b(5)];
ceq = [];
end
function y = min_weight(x)
b = x(1);
d1 = x(2);
d2 = x(3);
Z1 = x(4);
m = x(5);
y = ((pi*p)./4000).*(b*m.^2 *Z1.^2 * (1+a.^2))-((D(i).^2 - d(o).^2).*(l-b(w))-...
(n*d(p).^2 .* b(w))-((d1.^2 + d2.^2).*b));
end
Where now the missing values have to be inputed for example
bw = 3.5*m;
...
...
Get rid of the brackets for scalars like b(w) --> this will cause problems, use bw or b_w instead for all of those
回答(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!