How to add a less than constraint condition to solve the transcendental equation
1 回表示 (過去 30 日間)
古いコメントを表示
I have tried to solve the transcendental equation by Genetic algorithm. The fitness function used for the equations is given below:
function y = myFitnes(x)
y = ((cos(x(1)) + cos(x(2)) + cos(x(3)) + cos(x(4))-0.9*(pi/2)))^2...
+(cos(3*x(1)) + cos(3*x(2)) + cos(3*x(3)) + cos(3*x(4)))^2...
+(cos(5*x(1)) + cos(5*x(2)) + cos(5*x(3)) + cos(5*x(4)))^2 ...
+ (cos(7*x(1)) + cos(7*x(2)) + cos(7*x(3)) + cos(7*x(4)))^2;
end
The main code written to solve the above equation using Genetic algorithm is given below:
objFcn =@myFitnes;
nvars = 4;
LB = [0 0 0 0];
UB = [pi/2 pi/2 pi/2 pi/2];
[x, fval] = ga(objFcn,nvars,[],[],[],[],LB,UB);
How to add the constraint condition 0<x(1)<x(2)<x(3)<x(4)<pi/2; to solve the above equations.
2 件のコメント
Matt J
2018 年 1 月 7 日
Please indent your code so that it is fonted more readably (as I have done for you now)
採用された回答
Matt J
2018 年 1 月 7 日
編集済み: Matt J
2018 年 1 月 7 日
A=[1,-1,0,0;
0, 1,-1;0;
0, 0, 1,-1];
b=[0;0;0];
objFcn =@myFitnes;
nvars = 4;
LB = [0 0 0 0];
UB = [pi/2 pi/2 pi/2 pi/2];
[x, fval] = ga(objFcn,nvars,A,b,[],[],LB,UB);
4 件のコメント
Walter Roberson
2018 年 9 月 15 日
[1, -1, 0, 0]*[x1; x2; x3; x4] is x1-x2. Requiring that to be less than b(1)=0 is the condition x1-x2<=0. Add x2 to both sides to get x1<=x2
The A b matrix also encodes x2<=x3 the same way. Transitivity says you can then write x1 <= x2 <= x3 <= x4. The 0 at the beginning is expressed by lb 0. The const at the other end is ub const.
その他の回答 (1 件)
Walter Roberson
2018 年 1 月 7 日
objFcn =@myFitnes;
nvars = 4;
A = [1 -1 0 0;
0 1 -1 0;
0 0 1 -1]
b = [0;
0;
0];
LB = [0 0 0 0] + realmin; %disallow 0 exactly
UB = [pi/2 pi/2 pi/2 pi/2] * (1-eps); %disallow pi/2 exactly
[x, fval] = ga(objFcn, nvars, A, b, [], [], LB, UB);
This implements 0 < x(1) <= x(2) <= x(3) <= x(4) < pi/2 which is not exactly what you had asked for. Coding strict inequalities would require adding the nonlinear constraint function, which is possible in this case (since you do not have any integer constraints), but is not as efficient.
参考
カテゴリ
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!