Generating random complex numbers between -0.5 to 0.5 in Gatbx
이전 댓글 표시
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
dpb
2015년 1월 19일
>> which rep
'rep' not found.
>>
Looks like it's dependent on how that function works...
Hamza
2015년 1월 19일
dpb
2015년 1월 19일
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)
답변 (2개)
Roger Stafford
2015년 1월 19일
(rand(20,2)-.5) + (rand(20,2)-.5)*1i ;
댓글 수: 1
k i
2017년 9월 18일
thank you sir ,it is very much useful to me
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!