# Applying repeated functions

eddybob123
Hi everybody, I was just wondering; is there an easy way to define a repeated function? What I mean by this is applying a function f to a value x, and the result becomes the new x with the function applied to that, and so on, so on n times? Thank you all in advance.

SteveL27
Hi everybody, I was just wondering; is there an easy way to define a repeated function? What I mean by this is applying a function f to a value x, and the result becomes the new x with the function applied to that, and so on, so on n times? Thank you all in advance.

Do you mean is there a simple formula? Sometimes, sometimes not.

Denote f(f(f(x))) as f3(x) and so forth. Now if f(x) = x2 then f7(x) = x14. So in this case it's easy to calculate an explicit expression for an iterated function.

On the other hand if f(x) = sin x, then there's no simpler expression for f7(x) than simply sin7(x).

Homework Helper
I think he means nested functions. One common example used in programming is to calculate factorial by defining f(x) = x f(x-1), and defining f(0) = 1. In this case f(x) = x!, but there's no general method to handle something like sin(sin(sin ... (sin(x)) ... )).

Homework Helper
One common notation is

$$x_{n+1} = f(x_n).$$

Repeated application of the rule shows that ##x_{n+1} = \underbrace{f(f(f(\dots}_{\rm n~times} f(x_0)))\dots )##.

In general, it's hard to calculate the (n+1)th value without computing the previous n values. However, it is not quite so hard to calculate the "##n = \infty##" value (excuse the abuse of notation). In that case,

$$x_\infty = f(x_\infty).$$
This is not hard to solve numerically (without doing infinite iterations), and it tells you all the possible values your iterated function might converge to (or oscillate between), so long as such values, called "fixed points", exist. Which fixed point your iteration ends up at depends on the initial value of x=x0 that you pick

Matt Benesi
There are lots of cool things you can do with nested functions. I covered a few in this rather messy thread.

There is a good article on nested radicals over at Wolfram Mathworld, although it leaves out a few interesting things (such as the derivative trick I mentioned in the "messy" thread).

Here is an old thing I wrote on nested radicals.

Here is a rather messy thing I wrote about various nested functions and the derivative property.

Also, there are fractals, many of which use recursive functions, including this one from a formula I wrote yesterday (based on an old formula... but 4 dimensional and unique in its own way):

DavidHume
The J programming language provides a complete, consistent, executable version of mathematical notation (see jsoftware.com). For instance, we can use the "power" conjunction to apply a function to its result repeatedly.

So, if we define a function "f" which squares its input,

f =: 3 : 'y^2'

Here's an example of applying the function to some arguments

f 2 3 4
4 9 16

Since J is interactive, applying "f" to the vector "2 3 4" returns the vector "4 9 16".

Using the "power" conjunction "^:" to apply "f" once gives the same result:

f ^: 1 ] 2 3 4
4 9 16

Applying "f" to its argument twice:

f ^: 2 ] 2 3 4
16 81 256

Three times:

f ^: 3 ] 2 3 4
256 6561 65536

And so on.

eddybob123
But what if the function contains more than one variable: f(x,y_1), and that function is applied again with the result of the previous equation as x, and another variable y_2, and the result of that replacing x with another variable y_3, and so on until y_n. Is there a simple formula for that? (The symbol _ represents subscripts)

Homework Helper
But what if the function contains more than one variable?
Generally recursive functions are somewhat limited to something that would make sense. I doubt there's much use for sin(sin(sin(x))).

There is an applicaion for repeated versus recursive usage of a function, such as numerical integration of differential equations with a given initial condition, for example the path of an object affected by gravity and the drag of the atmosphere. In this case with a given initial velocity and position, accelerations are calculated and used to predict new velocities and positions, to predict a path, repeating the process one small time step per iteration.

eddybob123
I meant it just as a question, not its applications. Is there any way to represent repeated two variable functions? The one I am talking about being f(f(f(f(x,a),b),c),d)...

Matt Benesi
$f(x_0,y_0) = x_1,y_1$ or $g_0(x,y) = x_0,y_0$
$f(x_1,y_1) = x_2,y_2$ or $g_1(x,y) = x_1,y_1$
$f(x_n,y_n) = x_{n+1},y_{n+1}$ or $g_n(x,y) = x_{n+1},y_{n+1}$

You should define it in an easily understandable way.

There is an example with complex variables here.

There is also the simpler definition in the first paragraph about the Mset, similar to the ones I posted above: zn+1 = zn2 + c

There are a lot of ways to communicate ideas. Just do it in a way that is understandable and logical, unless you are submitting something to the ruling junta- then you must follow their rules, which are generally learned by paying money to institutions that pay them.. :D