필터 지우기
필터 지우기

Error:Too many input arguments in GA solver

조회 수: 2 (최근 30일)
Rajdeep Ghosh
Rajdeep Ghosh 2020년 8월 15일
편집: Mario Malic 2020년 8월 15일
Dear programmers
I need to minimize a single-objective function in ga having two(2) input variables. But the solver is showing an error:Too many input arguments. Please help.
function y = simple_fitness(x)
%SIMPLE_FITNESS fitness function for GA
y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
rng default % For reproducibility
FitnessFunction = @simple_fitness;
numberOfVariables = 2;
lb = [-3,-3];
ub = [3,3];
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub);

채택된 답변

Mario Malic
Mario Malic 2020년 8월 15일
편집: Mario Malic 2020년 8월 15일
function y = simple_fitness(x)
y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
end
rng default % For reproducibility
numberOfVariables = 2;
lb = [-3,-3];
ub = [3,3];
[x,fval] = ga(@(x)simple_fitness(x),numberOfVariables,[],[],[],[],lb,ub);
Now should be working.
  댓글 수: 12
Sara Boznik
Sara Boznik 2020년 8월 15일
This is what is saved in x and in fval is saved 1 constant ... 1.2344
Mario Malic
Mario Malic 2020년 8월 15일
편집: Mario Malic 2020년 8월 15일
[x,fval,exitflag,output,population,scores] = ga(___)
This is a code if one should further investigate about the solution, and maybe try to check the available ga options if solution is not the optimal one.
Also, since this function is quite straight forward, one could just generate meshgrid within the bounds, evaluate objective function and then find a minimum of it.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by