MATLAB Answers

Problem in using Genetic algorithm tool - Not enough input arguments

2 views (last 30 days)
Rui
Rui on 10 Aug 2012
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?

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by