random numbers uniformly distributed in log space

5 vues (au cours des 30 derniers jours)
I MK
I MK le 23 Mai 2012
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.

Réponses (1)

Walter Roberson
Walter Roberson le 23 Mai 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))

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by