generating logarithmically distributed numbers

How do I generate N numbers from X to Y, distributed logarithmically?

For example, if I wanted 4 numbers from 1 to 10, distributed logarithmically, these numbers would be roughly 1, 2, 5, and 10. But I'd like to compute the exact numbers.
bmihuraAsked:
Who is Participating?
 
ozoCommented:
e^(log(X)*i+log(Y)*(N-1-i))/(N-1)
for i=0..N-1
0
 
ozoCommented:
e^(log(1),
e^(log(1)*2+log(10))/3
e^(log(1)+2*log(10)/2
e^log(10)
0
 
ozoCommented:
e^(log(1),
e^(log(1)*2+log(10))/3
e^(log(1)+log(10)*2)/3
e^log(10)
0
 
ozoCommented:
equivalently
Y * (X/Y)^(i/(N-1))
0
 
bmihuraAuthor Commented:
Thanks, ozo, that got me most of the way there. I just needed to adjust your parentheses a little like this:

e^((log(X)*i+log(Y)*(N-1-i))/(N-1))
for i=0..N-1

I've attached some working C# code in case it will help anybody.

	// e^((log(X)*i+log(Y)*(N-1-i))/(N-1))
	// for i=0..N-1
	string s = "";
	double X = 10;
	double Y = 100;
	double N = 5;
	for (int i = 0; i < N; i++)
	{
		double value = Math.Exp((Math.Log(X) * i + Math.Log(Y) * (N - 1 - i)) / (N - 1));
		s += value + "\r\n";
	}
	MessageBox.Show(s);

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.