# Mathematica: Iterations

• Mathematica
Sarah rob
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 ????

Simon_Tyler
It's not quite clear exactly what you want, but here's something to maybe get you started

Code:
In:= 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:= repeat[{1,2},{3,4},5,2,f]
During evaluation of In:= f[f[f[f[f[{1,2}]]]]]
During evaluation of In:= f[f[f[f[f[{3,4}]]]]]
During evaluation of In:= f[f[f[f[f[f[f[f[f[f[{1,2}]]]]]]]]]]
During evaluation of In:= f[f[f[f[f[f[f[f[f[f[{3,4}]]]]]]]]]]
Out= {f[f[f[f[f[f[f[f[f[f[{1,2}]]]]]]]]]],f[f[f[f[f[f[f[f[f[f[{3,4}]]]]]]]]]]}