I want to repeat a function n times on a table, For n=2 I have the following code, How can I be sure that the function had run twice since my fc is differend every time?
smat = Table[{9, 8, 10}, {3}]
f[x_?Table] := ReplacePart[
x, {{2, 1} -> x[[2]][[1]] - #, {2, 2} -> x[[2]][[2]] + #}] &@ fc[x[[2]][[1]]];
fc[k_?NumericQ] := Count[RandomReal[{0, 1}, k], x_ /; x < .1]
Nest[f, smat, 2]
Acl covered the problems with the code pretty well, so I won’t. To answer your question, though, I’d first separate your functions
fandfcin separate cells, withfcbeing declared prior tof, and preface each cell withClear[<function name>]. Now, to test iffis being applied twice, temporarily replacefcwithor use another “dummy” value other than a, but it should be symbolic to increase readability. As a point of note,
{1,2,3} + a == {1 + a, 2 + a, 3 + a}, so iffis applied twice, each term inx[[2]][[1]]andx[[2]][[2]]will have2 aadded to it.Now, if you are unsure if
fcis working correctly by itself, I’d apply it to a number separate cases withoutf, first.