Problem in using Genetic algorithm tool - Not enough input arguments

조회 수: 1 (최근 30일)
Rui
Rui 2012년 8월 10일
I want to use GA to find the minimum of the function z=x^2+y^2.
I define the function:
function z=my_fun(x,y)
z=x.^2+y^2;
then I call the ga function:
ga(@my_fun,2)
but error occurs.
the error message is:
Error using my_fun (line 2) Not enough input arguments.
Error in validate>@(x)fitness(x,FitnessFcnArgs{:}) (line 136) fitness = @(x) fitness(x,FitnessFcnArgs{:});
Error in fcnvectorizer (line 14) y(i,:) = feval(fun,(pop(i,:)));
Error in makeState (line 47) Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in gaunc (line 41) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 351) [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by: Failure in user-supplied fitness function evaluation. GA cannot continue.
Could someone help me?

답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by