Skip to main content
added 259 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

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]

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]

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

edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
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++]]plist[[i]], 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]

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

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]

added 64 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
plist = Array[p, 3];
nlist = Range[Length @ plist] + 1;

Fold[fun[#1, #2[[1]]plist[[#2 - 1]], #2[[2]]#2, 0, 15]&,15] data&, Transpose[{nlistdata, plist}]]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

plist = Array[p, 3];
nlist = Range[Length @ plist] + 1;

Fold[fun[#1, #2[[1]], #2[[2]], 0, 15]&, data, Transpose[{nlist, plist}]]

fun[fun[fun[data, p[1], 2, 0, 15], p[2], 3, 0, 15], p[3], 4, 0, 15]

Also

Fold[fun[#1, ## & @@ #2, 0, 15] &, data, Transpose[{nlist, plist}]]

same result

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

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading