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.

采纳的回答

Matt J
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
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
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 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