4

I would like to test several values of intensity.

I need them to be spaced logarithmically from 1 to 1000. Yet I just use 1, 10, 100, 1000, but I would like to have more data point, let`s say 10.

How could I find 10 logarithmically spaced number between 1 and 1000 in Mathematica ?

500
  • 6,509
  • 8
  • 46
  • 80

3 Answers3

17

If a is start, c is end and b is number of intervals:

{a, b, c} = {1, 10, 1000};
t = (c/a)^(1/b) // N
a*t^Range[b]

1.99526
{1.99526, 3.98107, 7.94328, 15.8489, 31.6228, 63.0957, 125.893, 251.189, 501.187, 1000.}

I used N just to see better, what do we have.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
  • 1
    I was going to post something very similar but you beat me to it by 2 seconds. By the way, `Power` is `Listable` so you could simply do `a*t^Range[b]`. – Heike Oct 15 '11 at 14:48
  • 1
    @Heike, nice! Updated. I spotted this question from RSS 30 minutes after it was published. It's my 1st Mathematica answer, so I tried to be fast ..P – Nakilon Oct 15 '11 at 14:53
  • 1
    @Nakilon You could use `Range[0,b]` as Leonid did to get full list starting from `a`. – Alexey Popkov Oct 15 '11 at 15:09
7

Here is one way:

In[11]:= base = Block[{a}, a /. NSolve[a^9 == 1000, a][[-1, 1]]]
Out[11]= 2.15443

In[13]:= base^Range[0, 9]
Out[13]= {1., 2.15443, 4.64159, 10., 21.5443, 46.4159, 100., 
  215.443,464.159, 1000.}

EDIT

Here is a much shorter and more direct way to get the same:

In[18]:= N[10^Range[0, 3, 1/3]]

Out[18]= {1., 2.15443, 4.64159, 10., 21.5443, 46.4159, 100., 
215.443, 464.159, 1000.}
Leonid Shifrin
  • 22,449
  • 4
  • 68
  • 100
  • Thank you Leonid, would you mind explaining the use of "Block", "/." & the curious "[[-1,1]]". It works, but I can`t get a grasp at that syntax yet. – 500 Oct 15 '11 at 14:30
  • @500 I think it is much clearer just to use `NSolve[a^9==1000,a,Reals]`. Instead of `Block` one can use [Formal Symbol](http://reference.wolfram.com/mathematica/tutorial/LettersAndLetterLikeForms.html#173509264) [`\[FormalA]`](http://reference.wolfram.com/mathematica/ref/character/FormalA.html) with the same success: `base=\[FormalA]/.NSolve[\[FormalA]^9==1000,\[FormalA],Reals]//First`. "`/.`" is just [`ReplaceAll`](http://reference.wolfram.com/mathematica/ref/ReplaceAll.html). – Alexey Popkov Oct 15 '11 at 14:42
  • @500 I think, it is much easier to just use `base = N[Power[1000, 1/9]]`. Actually, `base` is a cubic root of `10`. Don't know what I was thinking. – Leonid Shifrin Oct 15 '11 at 16:10
  • Thank You ! I was actually looking into that. But could not find out how to get the nth roots. You answered that question to : Power & fraction ! – 500 Oct 15 '11 at 16:14
4

Solve the equation x ** 9 = 1000 -- then your numbers are: x ** 0, x ** 1, ... x ** 9.

note: where x ** y means x to the power of y

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192