random numbers uniformly distributed in log space
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Is there a function that can return n random numbers uniformly distributed in logspace?
The best solution I thought of involves randsample with logarithmic probability weights, but this is hack-y and inefficient.
Is there some input I can feed to random or some function I could apply to rand that would achieve what I want? Or, is there a known file on the file exchange that achieves this? I have searched, but to no avail.
Thanks in advance for your help.
0 Commenti
Risposte (1)
Walter Roberson
il 23 Mag 2012
log10 or ln ?
Assuming that you want the natural log of the n points to be uniformly distributed in the range A to B then
exp(A + (B-A)*rand(1,n))
Use 10.^ instead of exp() if you want log10.
Note that here A and B are expressed in log. If it is more convenient to you to have original values (e.g. 1000 instead of 3) then
LA = log(A); LB = log(B);
exp(LA + (Lb-LA) * rand(1,n))
or correspondingly
LA = log10(A); LB = log10(B);
10.^(LA + (Lb-LA) * rand(1,n))
0 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!