How to code to perform the following task?

2 ビュー (過去 30 日間)
Assen Beshr
Assen Beshr 2022 年 6 月 25 日
編集済み: dpb 2022 年 6 月 26 日
Locations = Location(randi(numel(Location),nPop,Num_DG));
% OR
min=[0 0 1 1];
max=[4738 4738 137 137];
VarSize=[1 nVar];
when the above two task is change by two varaible with complex number like
max=[4738+34i 4738+342i 137 137]; how to modify the code to perform the same tasks?
  10 件のコメント
dpb 2022 年 6 月 26 日
So, as noted above, a complex PRV is simply
rngReal=[0 4738];
rngImag=[0 342];
If you have multiple ranges and numbers of rng's to generate for each, you'll want to package the above in some caller-friendly function for ease of coding, but the technique is as shown.
There is no builtin RNG for complex variables to do a single substitution of one function for another; but, you'll have one when you've finished the above.
Of course, you've got to decide the underlying distribution of the real and imaginary parts to decide which generator to use; randi above will return only integer-valued values; rand will generate full-precision doubles but you'll have to scale to the desired range.
Torsten 2022 年 6 月 26 日
編集済み: Torsten 2022 年 6 月 26 日
Then do as "dpb" suggests.
lb = [254+112i,423+312i];
ub = [588+256i,745+1256i];
lb_real = real(lb(:));
ub_real = real(ub(:));
lb_imag = imag(lb(:));
ub_imag = imag(ub(:));
rand_real = lb_real + rand(size(lb_real)).*(ub_real-lb_real);
rand_imag = lb_imag + rand(size(lb_imag)).*(ub_imag-lb_imag);
random_numbers = (rand_real + 1i*rand_imag).'
random_numbers =
1.0e+03 * 0.5261 + 0.1303i 0.7147 + 1.1742i



dpb 2022 年 6 月 26 日
編集済み: dpb 2022 年 6 月 26 日
"...randi ... will return only integer-valued values; rand will generate full-precision doubles but you'll have to scale to the desired range."
The min/max ranges given were integral as were the original s PRNVs generated by the permute operation on the original s.
The first code snippet generates a vector of length Num_DG*nPop elements from the integers in the range 1:s(Num_DG).
The snippet defines Num_DG and nPop as constants; and so the permutation operation uses a specific reference to the s data as the number of possible elements to use in generating the subsequent V vector.
As noted in first comments, there is no corollary operation for this directly with complex variables; the OP will have to provide additional information on what V is used for to make some valid determination of what it means, if anything, when s is turned into a complex variable instead.
One presumes this is probably some Monte Carlo-like simulation and this was a part of a way to generate a set of RNVs for the subsequent calculation but we simply do not know enough to be able to provide a direct answer to the underlying problem.
My first suggestion of using fix(abs(s)) in lieu of s would let the code run; whether it has any use or not is another question entirely.
A more thorough understanding of the code would be required to know; it may well be that turning these values at this point in the code into complex isn't a proper thing to do at all -- but that the complex variables might come into play down in the bowels of the simulation.
If I had to really make a guess, that would be it -- the Q? asked isn't the one that should have been at all.

その他の回答 (0 件)


Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by