I'm having trouble with setting up a particular range in a loop for my programming. Now I have a defined range of data (not continuous numbers) that needs to be applied in a loop. Since the aim for my code is to generate functions/expressions with the range automatically, I need to figure out a way to applied those data.

The code is

MapThread[(Subscript[C, #1][x, y] := 
     Subscript[q, 2 #1 - 1] + 
      x*Subscript[q, 2 #1] - (Subscript[q, #2] + 
        y*Subscript[q, #2 + 1])) &, {Range[], Range[]}];

data for #1 is: 3, 4, 5, 4, 6, 6, 6, 6. data for #2 is: 1, 2, 4, 3, 1, 2, 3, 5.

As u can see from the code, I cannot simply define the range in the loop. My idea is to create a list for the data and maybe apply it in the loop? thx for ur help!

  • 2
    $\begingroup$ 1) Please provide an equivalent code without Subscript (unless your question actually pertains to Subscript)... it only occludes your intent 2) Why haven't you inserted your "data" for #1 and #2 instead of Range[] (which does nothing, since it needs at least 1 arg) 3) Please edit your posts to make it proper English. We like to avoid "u", "thx", "ur", etc. and keep it clean. $\endgroup$
    – rm -rf
    Jan 15, 2014 at 3:01
  • $\begingroup$ If the OP could describe as precisely as possible what it is that he/she wants to do, rather than provide a vague explanation and non-functional code, then maybe it will be possible to help. $\endgroup$
    – heropup
    Jan 15, 2014 at 3:13
  • $\begingroup$ Also, you should note that since the list for #1 contains repeated elements you're just redefining Subscript[c, #1][x, y] n times, which I guess isn't what you're after $\endgroup$ Jan 15, 2014 at 3:18

1 Answer 1


It looks like you are trying to define a collection of functions that are indexed by two variables #1 and #2. This code replaces #1 with i, #2 with j and defines all the functions within a Table.

Table[c[i_, j_, x_, y_] := q[2 j - 1] + x*q[2 i] - (q[j] + y*q[j + 1]), 
     {j, {1, 2, 4, 3, 1, 2, 3, 5}}, {i, {3, 4, 5, 4, 6, 6, 6, 6}}];

So now, for example, there are a collection of functions c indexed by the i and j, each defined in terms of x, y, and q[ ]. For example:

c[3, 4, x, y]
-q[4] - y q[5] + x q[6] + q[7]
  • $\begingroup$ +1 for a great effort in trying to understand the question. But I haven't the slightest idea on how close you could be from the "real" question :) $\endgroup$ Jan 15, 2014 at 4:21
  • $\begingroup$ @belisarius I guess I was hoping to prompt "but that's not what I meant" from the OP so we could figure it out... it seemed like an interesting mix of naivete (such as malformed Range[ ] comamnds) and sophistication (such as MapThread). $\endgroup$
    – bill s
    Jan 15, 2014 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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