Setting lower and upper bounds in 'ga' algorithm.

조회 수: 18 (최근 30일)
Ande Mandoyi
Ande Mandoyi 2020년 10월 10일
댓글: Learner123 2021년 4월 27일
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)

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 10일
See the lb and ub arguments: https://www.mathworks.com/help/gads/ga.html. For example
FitFcn = @myFitness;
nvars = 2;
lb = [-5 5];
ub = [5 5];
[x, fval] = ga(FitFcn, nvars, [], [], [], [], lb, ub)
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 10월 10일
I am glad to be of help!
Learner123
Learner123 2021년 4월 27일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by