# Indexing a value within a table function

Is what I'm looking to do possible? I know that I can get it to work with a for loop, but a table would make things much neater.

What I need to do while calculation the table below is to reset the variable l such that l = l - fretScale[y_]. l is initially set to 25.

l = 25 ;(* Nominal string length *)

fretScale[y_] := l*(1 - 1/2^(1/12)) // N;

Table[fretScale[y], {y, 1, 30, 1}]


What I did with the for loop (which works is this:

For[i = 1; y = 0, i < n + 1, i++,
y = l*(1 - 1/2^(1/12)) // N;
l = l - y


(Note, in the loop fretScale[y_] is defined as y, not as a defined function)

The table function above calculates the correct first fret position of 1.403, but keeps l fixed at 25 and I need to successively make l range from 25, 23.597, 22.273,...

The output I get for the table is:

{1.40314, 1.40314, 1.40314, ...}


what I want (and get for the for loop is)

{1.40314, 2.72753, 3.97759, ...}

• k[x_] := x - x*(1 - 1/2^(1/12)) // N; NestList[k, 25, 10] – Dr. belisarius Oct 6 '15 at 20:27

Here is one of many ways to do it with Table.

l = 25;
k = 1/2^(1/12) // N;
l - Table[l = k l, {30}]

{1.40314, 2.72753, 3.97759, 5.15749, 6.27116, 7.32233, 8.3145, 9.25099, 10.1349,
10.9692, 11.7567, 12.5, 13.2016, 13.8638, 14.4888, 15.0787, 15.6356, 16.1612,
16.6573, 17.1255, 17.5675, 17.9846, 18.3784, 18.75, 19.1008, 19.4319, 19.7444,
20.0394, 20.3178, 20.5806}

• ...and since it's all exponential: 25. Table[1 - 2^(-k/12), {k, 30}] – J. M. will be back soon Oct 7 '15 at 0:31
• @J.M.isback. Sure, that's another of the countless (well, I can't count them) of doing this with Table. BTW, glad to see you back. – m_goldberg Oct 7 '15 at 0:36