Re: Using values from inside a matrix for a new row

*To*: mathgroup at smc.vnet.net*Subject*: [mg122403] Re: Using values from inside a matrix for a new row*From*: "andre.robin3" <andre.robin3 at wanadoo.fr>*Date*: Thu, 27 Oct 2011 06:33:06 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <j89vb0$1st$1@smc.vnet.net>

There are many solutions, for example this 3 lines solution : initTable = {{1, 2, 3}} addNewLine[table_] := Append[table, Map[f, table[[-1]], {1}]] (* see remark (1) *) Nest[addNewLine, initTable, 10] Remarks : (1) if you prefer, you can use the equivalent syntax : addNewLine[table_] := Append[table, f /@ table[[-1]]] (*more concise,usefull, readable when you become used to mathematica *) addNewLine[table_] := Append[table, f /@ First[table]] (*closer to Shakespeare who doesn't use [[...]] at all ! *) (2) Thanks to your textual explanations, I have done a implementation that reflect the way you are thinking, not the way computers are working. That is precisely the way you should use mathematica : You are describing the problem in terms of "how I do it with Excel", (calculate one line from the line above). That is one solution, not bad, to describe want you want to do. I have kept this idea in the code. On the contrary, It is not a good idea to try to describe the problem in terms of "how a stupid software would do it" ("initialization", use of "variables i,j", "loop", ... type declaration ...). It is useless and parasitical for the mind, unless you have to deal with speed problem during the calculation, (you are far from this situation...). "Michelle A" <hfvballgurl33 at gmail.com> a écrit dans le message de news: j89vb0$1st$1 at smc.vnet.net... > Hello, > I am new to Mathematica and I am trying to create an array of values > that uses info from the line above. I'm thinking of it like how Excel > would do it but I'm not sure how to go about it in Mathematica. I've > been getting the RecursionLimit error when I try to call an earlier > element of the array. > > Here is what I'm thinking in a simplified form: > > Say I simply want to add a constant (1 here) to each element above. So > I want my answer to be like this: > > 1 2 3 > 2 3 4 > 3 4 5 > > f = {{1, 2, 3}, {f[[1, 1]] + 1, f[[1, 2]] + 1, f[[1, 2]] + 1}} and > continue to have it grow to be a 10x3 matrix. I know I'll need some > i's and j's but I can't get it to work. Do I need to initialize an > array or make a loop to just add one row at a time in a separate > step? > > Any help is greatly appreciated. Thank you > >