Generating random complex numbers between -0.5 to 0.5 in Gatbx
60 views (last 30 days)
Show older comments
i am trying to use the gatbx for a problem . in which functions like bs2rv , crtbase, crtbp, crtrp, Objfun, ranking , select, recombine , reins these functions are present.
now in the main
NIND = 40; % Number of individuals per subpopulations
MAXGEN = 15; % maximum Number of generations
GGAP = .9; % Generation gap, how many new individuals are created
NVAR = 32; % Number of variables
PRECI = 8; % Precision of binary representation
% Build field descriptor
FieldD = [rep([PRECI],[1, NVAR]); rep([-0.5-0.5i;0.5+0.5i],[1, NVAR]);...
rep([1; 0; 1 ;1], [1, NVAR])];
% Initialise population
Chrom = crtbp(NIND, NVAR*PRECI);
Phen = bs2rv(Chrom,FieldD);
what i am trying to do is to generate some random complex numbers between -0.5 to 0.5 .
in the FieldD vector i am specifying the upper bound and lower bound for my variable where i have written
rep([-0.5-0.5i;0.5+0.5i],
but this is giving me numbers like
-0.3863 - 0.3863i 0.3510 + 0.3510i
0.2961 + 0.2961i 0.2373 + 0.2373i
-0.1196 - 0.1196i 0.1039 + 0.1039i
0.2961 + 0.2961i -0.3706 - 0.3706i
-0.4843 - 0.4843i -0.4882 - 0.4882i
-0.3706 - 0.3706i -0.2412 - 0.2412i
-0.0373 - 0.0373i 0.3471 + 0.3471i
0.4176 + 0.4176i -0.4294 - 0.4294i
-0.1745 - 0.1745i 0.3784 + 0.3784i
-0.3706 - 0.3706i -0.2451 - 0.2451i
-0.4882 - 0.4882i 0.4098 + 0.4098i
0.0412 + 0.0412i 0.2882 + 0.2882i
0.3157 + 0.3157i -0.4725 - 0.4725i
-0.3863 - 0.3863i 0.3510 + 0.3510i
-0.4647 - 0.4647i 0.0098 + 0.0098i
0.4137 + 0.4137i 0.2451 + 0.2451i
-0.1353 - 0.1353i 0.3000 + 0.3000i
0.3000 + 0.3000i 0.4373 + 0.4373i
-0.0373 - 0.0373i -0.4333 - 0.4333i
0.1471 + 0.1471i -0.4373 - 0.4373i
in my Phen vector. this is missing numbers like -0.4373 + 0.4373i or +0.4373 - 0.4373i what can i do to make this happen ..
3 Comments
dpb
on 19 Jan 2015
Not knowing much about what this is really doing, just looking the routine doesn't seem tailored to handle complex variables.
Looks to me like you would either use Roger's solution or if you think you must use these routines, modify the routine to specifically handle complex.
The question then becomes is it simply a random sign between Re,Im parts you care about or do you want a "real" PRV over the complex plane?
b)
Answers (2)
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!