There has to be a simple solution for my question:
I have three functions and each uses the output from the previous function as its input:
x=1;
fx1 = 1 + x;
fx2 = %^2;
fx3 = %-2;
If I want three iterations of the code above
Nest[((1 + #)^2) - 2 &, 1, 3]
works and the result is as expected (62). However, my code is much longer and confusing than this example, so I had to assign names to the functions. If I try to do:
Nest[fx3@fx2@fx1[{x}] &, 1, 3]
it no longer works. I might simply not be using the Nest or other functions properly. Additionally, my first function contains a RandomVariate
on it that doesn't seem to work either once it is nested. For example, my code could look like:
x=1;
fx1 = RandomVariate[NormalDistribution[]] + x;
fx2 = %^2;
fx3 = %-2;
I would like to generate n loops referencing the functions by their names, where RandomVariate
produces a new value with each loop, and the value of x at the end is used as the initial value of x for the next loop. Ive tried, but I am much too new at this still. Any help is greatly appreciated!