Error,, too many input arguments!!

4 vues (au cours des 30 derniers jours)
Yasmin Tamimi
Yasmin Tamimi le 27 Mar 2011
function [x,fval] = yasmin
%% Fitness function (objective function) and number of variables
fitnessFcn = @(x) ga_test(x);
numberOfVariables = 1310;
A=[]; %% (2596x1310)
b=[]; %% (1310x1)
Aeq=[]; %% (20x220)
beq=[]; %% (220x1)
%% Decision variables are bounded (either zero or one)
LB = zeros(1,1310);
UB = ones(1,1310);
Bound = [LB;UB];
% Create an options structure to be passed to GA % Three options namely 'CreationFcn', 'MutationFcn', and % 'PopInitRange' are required part of the problem. %% Population size to be at least the value of Number of variables, so that %% the individuals in each population span the space being searched.
options = gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation, ... 'PopInitRange',Bound,'Display','iter','StallGenL',100,'Generations',150, ... 'PopulationSize',1310,'PlotFcns',{@gaplotbestf,@gaplotbestindiv});
[x,fval] = ga(fitnessFcn,numberOfVariables,A,b,Aeq,beq,LB,UB,[],options);
x
%%************************************************************************* %%*************************************************************************
% Mutation function to generate childrens satisfying the range and integer % constraints on decision variables.
function mutationChildren = int_mutation(parents,options,GenomeLength, ... FitnessFcn,state,thisScore,thisPopulation)
shrink = .01;
scale = 1;
scale = scale - shrink * scale * state.Generation/options.Generations;
range = options.PopInitRange;
lower = range(1,:);
upper = range(2,:);
scale = scale * (upper - lower);
mutationPop = length(parents);
% The use of ROUND function will make sure that childrens are integers.
mutationChildren = repmat(lower,mutationPop,1) + ... round(repmat(scale,mutationPop,1) .* rand(mutationPop,GenomeLength));
% End of mutation function
%%************************************************************************* %%*************************************************************************
function Population = int_pop(GenomeLength,FitnessFcn,options)
totalpopulation = sum(options.PopulationSize);
range = options.PopInitRange;
lower= range(1,:);
span = range(2,:) - lower;
% The use of ROUND function will make sure that individuals are integers.
Population = repmat(lower,totalpopulation,1) + ... round(repmat(span,totalpopulation,1) .* rand(totalpopulation,GenomeLength));
% End of creation function
When I run my m-file from the command line I write: x=ga(@ga_test,1310,A,b,Aeq,beq,LB,UB,[],options) OR [x,fval]=ga(@ga_test,1310,A,b,Aeq,beq,LB,UB,[],options)
and I get error using ga,, Too many input arguments
So I also tried : x=ga(yasmin) but I keep getting the same error.
Any help in this regard will be highly appreciated
Thanx in advance.
  2 commentaires
Atakan
Atakan le 28 Mar 2011
just try yasmin on command window,it will work...
Yasmin Tamimi
Yasmin Tamimi le 28 Mar 2011
Actually this is what I've done, but unfortunately it didn't work!!

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 27 Mar 2011
Which version are you using?
Please check
which -all ga
If you see anything other than an entry under the gads toolbox, you might have a conflicting function.
  13 commentaires
Walter Roberson
Walter Roberson le 29 Mar 2011
Are you trying to put in a numeric value for GenomeLength in a 'function' line? That isn't allowed. If you must, for some reason, override the value you are passing in (something that is more often a mistake than not) then use an assignment after the 'function' line, such as
GenomeLength = 1310;
Yasmin Tamimi
Yasmin Tamimi le 29 Mar 2011
Yes, that was my error. I've been using numeric values in a function line!! I run my example for both GenomeLength = 1310 which was wrong and the correct was for GenomeLength = 30 (#variables in the fitness function only)as defined in the reference manual.
Thank u very much for ur help.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by