From: Alex on
I want a table of N logorithmically spaced points between 0 and A. The problem is that I want only integers, and no repeats. So I cant use logspace since it will return 1.00001 1.00005 1.0009, etc, which all round down to 1. So is there a way to do something similar to logspace, but only return unique integers?
From: dpb on
Alex wrote:
> I want a table of N logorithmically spaced points between 0 and A. The
> problem is that I want only integers, and no repeats. So I cant use
> logspace since it will return 1.00001 1.00005 1.0009, etc, which all
> round down to 1. So is there a way to do something similar to logspace,
> but only return unique integers?

Not really as log(AnInteger) != AnotherInteger

How do you expect to make the irrational rational?

--
From: Walter Roberson on
Alex wrote:
> I want a table of N logorithmically spaced points between 0 and A. The
> problem is that I want only integers, and no repeats. So I cant use
> logspace since it will return 1.00001 1.00005 1.0009, etc, which all
> round down to 1. So is there a way to do something similar to logspace,
> but only return unique integers?

Ummm, so if I ask for 50 unique logarithmically spaced integers between 0 and
10, then how can that possibly be done?

Since the log of 0 is negative infinity, it cannot be included in the list of
points. But the way you have written your request, that's okay, because you
asked for points *between* the bounds, so we are allowed to interpret that as
excluding the upper and lower bound. But how close are we allowed to get to
the upper bound? If I A is 50 and the N'th point I generate is 49, is that
acceptable?

Must the integers be in obvious log relationship to each other, c^k for some
integer constant c and k being the index of points (1 to N) ? Or is it allowed
for the integers output to be rounding of the c^k for some real constant c ?
e.g., 1 3 7 20 55 148 403 1097 2981 8103 22026 is not immediately recognizable
to most people as being logarithmic, but that sequence is round(exp(1:10))

If the range is narrow enough and N is large enough that logspace() would
normally generate two numbers with the same integer part, what do you want to
have happen? Just drop out the duplicate so that there are fewer than N
points, or change the log basis so that even after duplicates are dropped,
thee are still N different values?


By the way, the condition for N logarithmically spaced points to fit "between"
0 and A, with no duplicates, and rounding used, is

N < 3.19294240059171220 * log(A-1/2) + 1

If this condition is satisfied, then you do not need to use a smaller than
normal log spacing to take into account duplicates.

By comparison, if N does not meet that criteria, but does meet the criteria

N < 4.93260692475286522 * log(A-1/2) + 1

then you will get either one or two duplicate points (after rounding.)
From: Walter Roberson on
dpb wrote:
> Alex wrote:
>> I want a table of N logorithmically spaced points between 0 and A. The
>> problem is that I want only integers, and no repeats. So I cant use
>> logspace since it will return 1.00001 1.00005 1.0009, etc, which all
>> round down to 1. So is there a way to do something similar to
>> logspace, but only return unique integers?
>
> Not really as log(AnInteger) != AnotherInteger
>
> How do you expect to make the irrational rational?

The criteria for points to be logarithmatically spaced is that (to within
roundoff error), X(2:end) ./ X(1:end-1) is a constant. Or, to phrase it
another way, that diff(log(X)) is a constant.

Example of logarithmically spaced integers:

1 2 4 8 16 32 64 128

diff(log(X)) for this returns a vector consisting of copies of log(2)
From: Alex on
As a specific example:

I want 256 integer points ~ log spaced ranging between 0 (or 1 if you really want to use logspace) and 65536. If I run logspace, I get a bunch of duplicates. If I remove the duplicates, I have < 256 points (it has to be 256).

The solution I came up with is to just look at the place where logspace stops duplicating (around 30) and then do a logspace of 226 points between 30 and 65536 and then just add 1:30 to the left of the array.


Walter Roberson <roberson(a)hushmail.com> wrote in message <ho0prd$cn1$1(a)canopus.cc.umanitoba.ca>...
> Alex wrote:
> > I want a table of N logorithmically spaced points between 0 and A. The
> > problem is that I want only integers, and no repeats. So I cant use
> > logspace since it will return 1.00001 1.00005 1.0009, etc, which all
> > round down to 1. So is there a way to do something similar to logspace,
> > but only return unique integers?
>
> Ummm, so if I ask for 50 unique logarithmically spaced integers between 0 and
> 10, then how can that possibly be done?
>
> Since the log of 0 is negative infinity, it cannot be included in the list of
> points. But the way you have written your request, that's okay, because you
> asked for points *between* the bounds, so we are allowed to interpret that as
> excluding the upper and lower bound. But how close are we allowed to get to
> the upper bound? If I A is 50 and the N'th point I generate is 49, is that
> acceptable?
>
> Must the integers be in obvious log relationship to each other, c^k for some
> integer constant c and k being the index of points (1 to N) ? Or is it allowed
> for the integers output to be rounding of the c^k for some real constant c ?
> e.g., 1 3 7 20 55 148 403 1097 2981 8103 22026 is not immediately recognizable
> to most people as being logarithmic, but that sequence is round(exp(1:10))
>
> If the range is narrow enough and N is large enough that logspace() would
> normally generate two numbers with the same integer part, what do you want to
> have happen? Just drop out the duplicate so that there are fewer than N
> points, or change the log basis so that even after duplicates are dropped,
> thee are still N different values?
>
>
> By the way, the condition for N logarithmically spaced points to fit "between"
> 0 and A, with no duplicates, and rounding used, is
>
> N < 3.19294240059171220 * log(A-1/2) + 1
>
> If this condition is satisfied, then you do not need to use a smaller than
> normal log spacing to take into account duplicates.
>
> By comparison, if N does not meet that criteria, but does meet the criteria
>
> N < 4.93260692475286522 * log(A-1/2) + 1
>
> then you will get either one or two duplicate points (after rounding.)