random numbers uniformly distributed in log space
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 23 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!