Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by acl, halirutan, Szabolcs, Artes, Mr.Wizard Dec 15 '12 at 0:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5  
Duplicate: mathematica.stackexchange.com/q/13226/5 –  rm -rf Dec 14 '12 at 14:20
1  
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. –  WalkingRandomly Dec 15 '12 at 9:36

2 Answers 2

up vote 16 down vote accepted

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.

share|improve this answer

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

Update

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&.

share|improve this answer
    
Thanks, this is just what I wanted! –  Will Vousden Dec 14 '12 at 14:15

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