Mathematica: Iterations

  • Mathematica
  • Thread starter Sarah rob
  • Start date
  • #1
16
0
If I have 2 list which are made up of pairs of numbers
e.g.
list1 = {{4, 5}, {2, 10}, {0, 15}}
list2 = {{5, 2}, {3, 7}, {1, 12}}
is there a way I can apply a function (that I have already created, f[x_]) on the lists which runs for e.g. 5 iterative steps with list1 then apply the same function to list2 for a further 5 iterations (iteration steps 6 - 10) , list1 for ieterations 11 - 15, list2 for steps 16 - 20 etc ...

I have been able to use one list using NestList but cant incorporate
alternating 2 list any suggestions ????
 

Answers and Replies

  • #2
313
1
It's not quite clear exactly what you want, but here's something to maybe get you started

Code:
In[1]:= repeat[list1_,list2_,n_,m_,f_]:=Module[{l1=list1,l2=list2},
                         Do[ Print[l1=Nest[f,l1,n]]; Print[l2=Nest[f,l2,n]],{m}];{l1,l2}]

It does m steps. Each time it nests f n times on list1 and list2.
I've added the Print[] statements so that you can see what's happening.
E.g.

Code:
In[2]:= repeat[{1,2},{3,4},5,2,f]
During evaluation of In[2]:= f[f[f[f[f[{1,2}]]]]]
During evaluation of In[2]:= f[f[f[f[f[{3,4}]]]]]
During evaluation of In[2]:= f[f[f[f[f[f[f[f[f[f[{1,2}]]]]]]]]]]
During evaluation of In[2]:= f[f[f[f[f[f[f[f[f[f[{3,4}]]]]]]]]]]
Out[2]= {f[f[f[f[f[f[f[f[f[f[{1,2}]]]]]]]]]],f[f[f[f[f[f[f[f[f[f[{3,4}]]]]]]]]]]}
 

Related Threads on Mathematica: Iterations

Replies
1
Views
2K
Replies
2
Views
2K
Replies
4
Views
3K
Replies
5
Views
3K
Replies
4
Views
2K
Replies
9
Views
2K
  • Last Post
Replies
1
Views
2K
Replies
7
Views
3K
  • Last Post
Replies
1
Views
3K
Replies
4
Views
704
Top