Function Repository Resource:

PowerSubdivide

Source Notebook

Subdivide an interval such that the ratio of subsequent elements is constant

Contributed by: Sander Huisman

ResourceFunction["PowerSubdivide"][xmax,n]

generates the list of values obtained by subdiving the interval from 1 to xmax into n parts such that the ratio of subsequent elements is constant.

ResourceFunction["PowerSubdivide"][xmin,xmax,n]

generates the list of values obtained by subdiving the interval from xmin to xmax into n parts such that the ratio of subsequent elements is constant.

Details and Options

ResourceFunction["PowerSubdivide"] effectively behaves like Subdivide, but in "log-space".
ResourceFunction["PowerSubdivide"][, n] generates a list of length n+1.

Examples

Basic Examples (1) 

Subdivide the range 10–10000 in 3 steps:

In[1]:=
ResourceFunction["PowerSubdivide"][10, 10000, 3]
Out[1]=

Scope (3) 

With two arguments, the start of the sequence is assumed to be 1:

In[2]:=
ResourceFunction["PowerSubdivide"][1000, 10]
Out[2]=

PowerSubdivide works on symbolic entries:

In[3]:=
ResourceFunction["PowerSubdivide"][a, b, 4]
Out[3]=

xmin can be larger than xmax:

In[4]:=
ResourceFunction["PowerSubdivide"][1000, 10, 4]
Out[4]=

Applications (1) 

PowerSubdivide gives points that are "logarithmically useful" for plotting on a logarithmic scale:

In[5]:=
ListLogLogPlot[
 Table[{x, x^2}, {x, ResourceFunction["PowerSubdivide"][10, 10^6, 40]}]]
Out[5]=

Properties and Relations (4) 

The ratio between subsequent values is constant:

In[6]:=
Ratios[ResourceFunction["PowerSubdivide"][a, b, 8]]
Out[6]=

PowerSubdivide is related to Subdivide:

In[7]:=
ResourceFunction["PowerSubdivide"][10, 20, 8] == Exp[Subdivide[Log[10], Log[20], 8]]
Out[7]=

Negative and positive end points results in intermediate values in the complex plane:

In[8]:=
ComplexListPlot[ResourceFunction["PowerSubdivide"][-10, 25, 40]]
Out[8]=

Calculate the geometric mean of two values:

In[9]:=
ResourceFunction["PowerSubdivide"][6.0, 10.0, 2][[2]]
Out[9]=

Compare to the built-in function:

In[10]:=
GeometricMean[{6.0, 10.0}]
Out[10]=

Possible Issues (3) 

If the start or end is a negative number, intermediate values might be complex numbers:

In[11]:=
ResourceFunction["PowerSubdivide"][-1.0, 1.0, 10]
Out[11]=

If both end points are negative real numbers, Chop might be needed to remove approximate zeros:

In[12]:=
values = ResourceFunction["PowerSubdivide"][-1.0, -100.0, 10]
Out[12]=
In[13]:=
Chop[values]
Out[13]=

Because Log(0) equals -, all but the last entry will be 0:

In[14]:=
ResourceFunction["PowerSubdivide"][0, 100, 10]
Out[14]=

Neat Examples (1) 

Connect pairs of random complex numbers:

In[15]:=
SeedRandom[1];
ComplexListPlot[
 ResourceFunction["PowerSubdivide"][##, 40] & @@@ RandomComplex[{-10 - 10 I, 10 + 10 I}, {100, 2}], Joined -> True]
Out[16]=

Publisher

SHuisman

Version History

  • 1.0.0 – 26 June 2019

License Information