Setting lower and upper bounds in 'ga' algorithm.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ande Mandoyi
le 10 Oct 2020
Commenté : Learner123
le 27 Avr 2021
I am trying to find the global minimum of the Ackley function using a genetic algorithm 'ga'. My code works fine until i try to add lower and upper bounds then I get errors. Please help me add the bounds to my code.
function y = myFitness(x)
y = -20.*exp(-0.2.*sqrt(0.5.*(x(1).^2+ x(2).^2))) - exp(0.5.*(cos(2.*pi.*x(1)))+(cos(2.*pi.*x(2))))+exp(1)+20;
end
clc
FitFcn = @myFitness;
nvars = 2;
lb = [-5 5];
ub = [5 5];
[x, fval] = ga(FitFcn, nvars)
0 commentaires
Réponse acceptée
Ameer Hamza
le 10 Oct 2020
FitFcn = @myFitness;
nvars = 2;
lb = [-5 5];
ub = [5 5];
[x, fval] = ga(FitFcn, nvars, [], [], [], [], lb, ub)
3 commentaires
Learner123
le 27 Avr 2021
Hi,
I have a similar issue. When I set lb and ub
I am getting an error.
Error using ga
Too many input arguments.
Any help is greatly appreciated. Thanks in advance
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Genetic Algorithm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!