1

I'd like to use the Table command without defining n, so that I can have a list of n arguments.

It is possible for the Sum command, but I guess not for the Table command, or is it? Something like

n = 5; eSO = Table[e[i], {i, 1, n}]; ebar[1] = EBAU - Sum[ebar[i], {i, 2, n}]; 
a[1] = A - Sum[a[i], {i, 2, n}]; b[1] = B - Sum[b[i], {i, 2, n}];

Cost = Table[1/2/a[i]*(ebar[i] - e[i])^2 + b[i]*(Sum[e[i], {i, n}])^2 /2, {i, 1, n}];

FOC = Table[D[Sum[Cost[[i]], {i, n}] == 0, e[i]], {i, 1, n}];

solsSO = eSO /. Solve[FOC, eSO];

solsSO = Flatten[solsSO];

ESO = Simplify[Sum[solsSO[[i]], {i, n}]]

but a bit more complicated in the end.

corey979
  • 23,947
  • 7
  • 58
  • 101
Max M
  • 113
  • 4
  • If you want that your m is not fixed but variable you could try something like: wi=Table[Table[Sin[i],{i,1,m}],{m,1,10}] – partial81 Jun 25 '12 at 13:27
  • I'm not sure I understand you correctly. Are you looking for this: Table[w[i], {i, {1, 2, 4, 3, 7, 2, 11}}], i.e. calling Table with a list of predefined index values? – István Zachar Jun 25 '12 at 13:30
  • Id like a list with dimension n, so id get.

    {w[1],w[2],...,w[n-1],w[n]}

    – Max M Jun 25 '12 at 13:51
  • 2
    You might like to have a look at this question, which demonstrates how to represent indeterminate-length (or infinite) lists in Mathematica. – Oleksandr R. Jun 25 '12 at 15:46
  • @OleksandrR. Thx but that seems a bit over my head. – Max M Jun 26 '12 at 10:30
  • 1
    I can't think of a way of doing this atm, but you might consider changing the title of your post to attract more attention. As I see it, the problem boils down to solving a system of equations with a indeterminate number of variables. – sebhofer Jun 27 '12 at 07:48
  • @sebhofer I probably stick to what you said about just checking my pen and paper results. To you last remark: It rather boils down to solving a system of equations where the number of equations is indeterminate. – Max M Jun 28 '12 at 12:19

1 Answers1

3

It's not possible because it makes as much sense as wanting to have list of n elements with n being undefined. The most similar thing you can do is to have a symbolic representation of that, that evaluates to what you want when n gets a numeric value. For that, you can either define your own

symbolicTable[exp_, it:{_, __?NumericQ| _List}]:=Table[exp, it]

If you then use symbolicTable just like Table, it will only evaluate when the iterator bounds are numeric and remain unevaluated when they are not.

ooor, just turn off the warning message you get when you try to use Table with a non-numeric argument

Off[Table::iterb]
Rojo
  • 42,601
  • 7
  • 96
  • 188
  • Thx for you reply, but does this really help me with my problem? Maybe, I dont really understand your proposal. I still wont be able to have a list with n arguments then, will I? – Max M Jun 25 '12 at 13:23
  • 1
    @Max: we might be more helpful if you tell us your actual problem, that is, the problem that requires this construction you speak of. – J. M.'s missing motivation Jun 25 '12 at 13:25
  • Its a rather simple optimization in economics. n would be the number of countries for which I have some cost function over which i minimize. Therefore I d like to have a list for the n countries where each argument represents one country, then do the differentiation and solve it. (still haveing trouble using minimize or sth similar). I can understand if that doesnt work since the program probably needs appropiate bounds for the list and the differentiation. if wi = Table[w[i], {i, 1, m}] is already not possible then the rest wont be either, i guess. – Max M Jun 25 '12 at 13:38
  • @MaxM So do you want to do an analytical or a numerical calculation? – sebhofer Jun 25 '12 at 14:03
  • Analytical. I ve done it with pen and paper, but would like to verify it and since i wanna do some further calculation with would be a bit messy it would be nice to have it in mathematica as well for numerical simulation. – Max M Jun 25 '12 at 14:08
  • 1
    @MaxM, I don't think Table can be used like that for analytical problems. You probably have to adapt your question giving more specifics of the problem at hand, to get real help – Rojo Jun 25 '12 at 14:13
  • @MaxM I agree with Rojo, it would definitely help do see a few equations to illustrate the problem better. On a more general note: If you solved your problem by hand already, I would stick to checking the result numerically for a few cases and start using Mathematica from there. – sebhofer Jun 25 '12 at 14:19
  • I just copied and pasted it now, id love to be able to include it in a better way, but i just couldnt find out how.

    when u run the lines you will see that the solution does not depend on N. We call this the social planner solution. I dont know how much it would help to go into the problem?

    It some quadratic cost function and a quadratic Damage function of the sum of emissions. e_i is supposed to be emissions and e_bar is Business as Usual emissions. the a_i and b_i are just to have heterogeneous countries

    – Max M Jun 25 '12 at 15:00
  • @MaxM: You can include code to the original post (just as you did) and you can format blocks of code by selecting it and hitting Ctrl+K. Also, you can remove unwanted comments by clicking on the small X that appears next to them when you move your mouse over. – István Zachar Jun 25 '12 at 15:16
  • @IstvánZachar Thx. – Max M Jun 25 '12 at 15:23