How to add a less than constraint condition to solve the transcendental equation
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Roy Francis
el 7 de En. de 2018
Comentada: Umair Naeem
el 16 de Sept. de 2018
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 comentarios
Matt J
el 7 de En. de 2018
Please indent your code so that it is fonted more readably (as I have done for you now)
Respuesta aceptada
Matt J
el 7 de En. de 2018
Editada: Matt J
el 7 de En. de 2018
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 comentarios
Walter Roberson
el 15 de Sept. de 2018
[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.
Más respuestas (1)
Walter Roberson
el 7 de En. de 2018
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.
Ver también
Categorías
Más información sobre Genetic Algorithm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!