If p
is fixed (at, say, p0
) in each iteration and only n
is changing, you can use Nest
:
k = 3;
i = 1;
Nest[fun[#, p0, ++i, 0, 15] &, data, k]
fun[fun[fun[data, p0, 2, 0, 15], p0, 3, 0, 15], p0, 4, 0, 15]
Alternatively,
First @ Nest[{fun[#[[1]], p0, #[[2]], 0, 15], #[[2]] + 1} &, {data, 2}, k]
fun[fun[fun[data, p0, 2, 0, 15], p0, 3, 0, 15], p0, 4, 0, 15]
If p
varies in each iteration taking values in a specified list:
plist = Array[p, 3];
nlist = Range[Length @ plist] + 1;
Fold[fun[#1, plist[[#2 - 1]], #2, 0, 15] &, data, nlist]
fun[fun[fun[data, p[1], 2, 0, 15], p[2], 3, 0, 15], p[3], 4, 0, 15]
Also
i = 1; Nest[fun[#, plist[[i]], ++i, 0, 15] &, data, 3]
Fold[fun[#1, #2[[1]], #2[[2]], 0, 15]&, data, Transpose[{nlist, plist}]]
Fold[fun[#1, ## & @@ #2, 0, 15] &, data, Transpose[{nlist, plist}]]
same result
If p
is fixed (at, say, p0
) in each iteration and only n
is changing
k = 3;
i = 1;
Nest[fun[#, p0, ++i, 0, 15] &, data, k]
fun[fun[fun[data, p0, 2, 0, 15], p0, 3, 0, 15], p0, 4, 0, 15]