cant find cause of non-singleton

Dear All,
I am using ga tool to optimize a vector for A*x-B=0
I conclude with the help of this forum http://www.mathworks.co.uk/matlabcentral/answers/41852-ga-fitness that a fitness function like this:
FitnessFcn = @(x)sum(abs(bsxfun(@minus,sum(bsxfun(@times,A,x),2),B)),1)
is working for the example below for A <5x4>
A =
2.1000 3.4000 101.0000 -2.0000
1.1000 -89.0000 33.0000 56.0000
-49.0000 -0.1900 92.0000 31.0000
4.2000 5.2000 0.1000 19.0000
40.0000 22.0000 12.0000 44.0000
and B <5x1>
B =
104.5000
1.1000
73.8100
28.5000
118.0000
By using [x]=ga(FitnessFcn,4)
But when I import file A <2100x24> and B <2100x1> (checked in the workspace tab)
I take :
??? Error using ==> bsxfun
Non-singleton dimensions of the two input arrays must match each other.
Error in ==> @(x)sum(abs(bsxfun(@minus,sum(bsxfun(@times,A,x),2),B)),1)
Error in ==> validate>@(x)fitness(x,FitnessFcnArgs{:}) at 136
fitness = @(x) fitness(x,FitnessFcnArgs{:});
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> makeState at 47
Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 279
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
I would be really grateful for your help since its really odd for me this behavior. Thanks for your time
Chris

2 commentaires

chris
chris le 23 Juin 2012
forgot to say I am using [x]=ga(FitnessFcn,24) in the second case
Jan
Jan le 23 Juin 2012
Dear chris, you can edit the original message instead of adding important details as a comment.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 23 Juin 2012

0 votes

Usually dbstop if error helps to reveal such problems. Then Matlab stops, when the error occurs and you can inspect the current dimensions of the variables.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by