How to add a less than constraint condition to solve the transcendental equation
조회 수: 2 (최근 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!