Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have some initial values such as L1 list:

L1={10,20,30,40,50};

I want to use the L1 list and do some calculation that the result will be like :

L2={110,120,130,140,150};

Now I want to use this L2 list instead of L1 list and execute my Do loop again with this new initial Values. And this iteration will be performed 5 times and in each iteration, I want to replace my previous list with the new calculated list. A Do loop like below:

1st. Iteration : use L1 list and result will be L2 list

2nd. Iteration : use L2 list and result will be L3 list

3rd. Iteration : use L3 list and result will be L4 list

4th. Iteration : use L4 list and result will be L5 list

5.th Iteration : use L5 list and result will be L6 list

End

After 5 iterations, the final result will be L6 list values.

I have no idea to do this kind of iteration! Could anyone help me, please ?!

share|improve this question

closed as off-topic by Kuba, rasher, RunnyKine, m_goldberg, bobthechemist Apr 4 at 14:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, rasher, RunnyKine, m_goldberg, bobthechemist
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Have a look at Nest. –  b.gatessucks Apr 4 at 8:55

1 Answer 1

up vote 5 down vote accepted

E.g, function squares list elements:

l1 = {1, 2, 3, 4, 5}

{l1, l2, l3, l4, l5, l6} = NestList[#^2 &, l1, 5]

(*

{{1, 2, 3, 4, 5}, {1, 4, 9, 16, 25}, {1, 16, 81, 256, 625}, {1, 256, 
  6561, 65536, 390625}, {1, 65536, 43046721, 4294967296, 
  152587890625}, {1, 4294967296, 1853020188851841, 
  18446744073709551616, 23283064365386962890625}}

*)

This puts the results in lists l1...l6.

If you only care about final result, replace NestList with Nest

share|improve this answer

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