Number of variables (NVARS) must be a positive integer.
27 views (last 30 days)
Show older comments
I want to run a project using genetic algorithm but I get this error every time.
I know what is it but I don't know how to fix it.
this is my project that I attached and the main function is GAmodule.
you can start with these numbers :
235
2
1
4
0
0
0
10
0
0
5
0
10
0
0
1000
g
700
Thank you
1 Comment
Accepted Answer
Star Strider
on 23 Aug 2014
Edited: Star Strider
on 23 Aug 2014
In this line (Line 163):
[x,fval]=ga(@(x) penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),(nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof,options);
the ga function is taking this value:
(nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof
to be ‘nvars’. It has to be an integer >0. I would use the ceil function to round it up to the next integer value, and include a check that it is >0.
For example, put this assignment and if block somewhere before your ga call:
Nvars = ceil((nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof);
if Nvars <= 0
error('NVARS must be greater than zero.')
end
then when it meets the criteria, use ‘Nvars’ (or whatever you want to call it) in your ga call.
2 Comments
More Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!