Possible Duplicate:
How can I get exactly 5 logarithmic divisions of an interval?

I want to use Table to generate a list of items, but want the indices to be logarithmically spaced. Is there a simple way of doing this, or will I have to explicitly run linearly spaced indices through Exp to get my list?

  • 5
    $\begingroup$ Duplicate: mathematica.stackexchange.com/q/13226/5 $\endgroup$
    – rm -rf
    Dec 14, 2012 at 14:20
  • 1
    $\begingroup$ Its asked in a different way though...more general for a start and it is targetted towards MATLABers. Personally i'd have left this up. $\endgroup$ Dec 15, 2012 at 9:36

2 Answers 2


Here's a somewhat simpler way:

 logspace[a_, b_, n_] := 10.0^Range[a, b, (b - a)/(n - 1)]

This gives a sequence starting at 10^a and ending at 10^b, with n points logarithmically spaced, as does MATLAB's logspace() function.


I don't belive there is a build in function for this, however you can easily do it using Range

 fSpace[min_, max_, steps_, f_: Log] :=  
      InverseFunction[f] /@ Range[f@min, f@max, (f@max - f@min)/(steps - 1)]

Inverse functions are being used so it'll give warnings in cases where you should be cautius, however it works for Log and other invertible functions.

 fSpace[1, 1000, 4]

{1, 10, 100, 1000}

{fSpace[1, 1000, 30, Sqrt[#] &], fSpace[1, 1000, 30]} // ListPlot

Image showing both logspacing and Sqrt spacing


I just discovered that you can in fact do even better out of the box by inverting the function only on the input range:

 fSpace[min_, max_, steps_, f_: Log] := 
  InverseFunction[ConditionalExpression[f[#], min < # < max] &] /@ 
  Range[f@min, f@max, (f@max - f@min)/(steps - 1)]

This still doesn't work arbitrarily, however it does help for instance selecting the positive square root in #^2&.

  • $\begingroup$ Thanks, this is just what I wanted! $\endgroup$ Dec 14, 2012 at 14:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.