Help to Run Genetic Algorithm

1 次查看(过去 30 天)
Rafael Zanetti
Rafael Zanetti 2020-11-24
评论: Stephan 2020-11-25
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 个评论
Rafael Zanetti
Rafael Zanetti 2020-11-25
Hi Stephan, I attached the complete paper , so we have five independent variables that has lower and upper boundaries:
20<=b>=35;
15<=d1>=32;
30<=d2>=50;
18<=Z1>=25;
1<=m>=4;
The constraints are:
  1. b(1)-F(s);
  2. b(2)-(F(s)./F(p));
  3. b(3)-d(1).^3;
  4. b(4)-d(2).^3;
  5. ((1+a).*m.*z(1)./2)-b(5)
And maybe I could have undertood the error mine, I had not define the variables (b,d1,d2,Z1,m) as a correct argument (x(1),x(2),x(3),x(4),x(5)).
You are correct about the suspicious, they are all scalars and I have to correct the multipliers in the function. I will try run with the corrections and I will bring if it works or not.
Once again, I thank you so much Stephan.
Stephan
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 CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by