Help to Run Genetic Algorithm
이전 댓글 표시
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일
Please attach the full Matlab code you have. It appears that the site 47 would be useful from the atached .pdf
Rafael Zanetti
2020년 11월 25일
What about Site 47 of the document and please elaborate what relations are:
D(i)
d(o)
b(w)
d(p)
F(s)
F(p)
--> For Matlab they all are EITHER interpreted ans functions with input argument inside the brackets - this is not the case i suspect OR they are interpreted as arrays, where you are interested in the value at the index that is represented by the variable inside the brackets. I also assume this is not the case - i suspect they are all scalars (?)
Also you use a addtionally vector b of size 1x5 in your constraint function - it is undefined
None of those are declared as variables in your code.
From the pdf-attachment we can learn:
b = x(1);
d1 = x(2);
d2 = x(3);
z1 = x(4)
m = x(5);
Please clarify
Rafael Zanetti
2020년 11월 25일
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개)
카테고리
도움말 센터 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!