Output of a Function as a Constraint in Genetic Algorithm
Afficher commentaires plus anciens
Hello,
I am trying to use the genetic algorithm to find the minimum value to a function.
My cost function is
function y=FitnessFcn(x)
y=abs(x(1));
end
My Constraint Function:
function [c, c_eq] =Constraints_CW(x)
format long;
c=[
abs(Compute(x(1))); ];
c_eq=[];
end
Where Compute
function X=Compute(x)
r0=[100; 100; 100;];
v0=[0;0;0];
%Initial Condition Vector
IC=[r0; v0];
%ODE 45 parameters
tol=1e-6;
options=odeset('RelTol',tol,'AbsTol',[tol tol tol tol tol tol]);
N=1;
M=10000;
time1=linspace(0,N,1000);
time2=linspace(N,M,9000);
time3=linspace(0,10000,10000);
%Integrator to solve the 2BP
[t,x1]=ode45(@(t, CW) CW_Thrust(t, CW, x ), time1, IC, options);
IC2=x1(1000,:)';
[t,x2]=ode45('CW', time2, IC2, options);
[t,x3]=ode45('CW', time3, IC2, options);
X=vertcat(x1,x2);
X=X(10000,2);
end
The idea is to iterate through values of x(1), pass them into the Compute function and return the last element of X which is then computed in the cost function.
Nothing seems to be happeniing when I run it.
Thanks!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Genetic Algorithm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!