## Documentation Center |

Iterate a function

This functionality does not run in MATLAB.

f @@ n_fnest(f,n)

`f@@n` represents the `n`-fold
iterate `x -> f(f(...(f(x))...))` of the function `f`.

The statement `f@@n` is equivalent to the call `_fnest(f,
n)`.

For positive `n`, `f@@n` is
also equivalent to `_fconcat(f $ n)`.

`f@@0` returns the identity map `id`.

If `f` is a function
environment with the slot `"inverse"` set, `n` can
also be negative. Cf. Example 2.

Iteration is only reasonable for functions that accept their
own return values as input. Note that `fp::fixargs` is a handy
tool for converting functions with parameters to univariate functions
which may be suitable for iteration. Cf. Example 3.

For a nonnegative integer `n`, `f@@n` is
equivalent to an `_fconcat` call:

f@@4, (f@@4)(x)

`@@` simplifies the composition of symbolic
iterates:

(f@@n)@@m

The iterate may be called like any other MuPAD^{®} function.
If `f` evaluates to a procedure and `n` to
an integer, a corresponding value is computed:

f := x -> x^2: (f@@n)(x) $ n = 0..10

delete f:

For functions with a known inverse function, `n` may
be negative. The function `f` must have been declared
as a function environment with
the `"inverse"` slot. Examples of such functions
include the trigonometric functions which are implemented as function
environments in MuPAD:

sin::"inverse", sin@@-3, (sin@@(-3))(x)

`@@` can only be used for functions that accept
their own output domain as an input, i.e.,
for
some set *M*.
If you want to use `@@` with a function which needs
additional parameters, `fp::fixargs` is a handy tool to generate
a corresponding univariate function. In the following call, the function `f:
x -> g(x, p)` is iterated:

g := (x, y) -> x^2 + y: f := fp::fixargs(g, 1, p): (f@@4)(x)

delete g, f:

`@`|`fp::fixargs`|`fp::fold`|`fp::nest`|`fp::nestvals`

Was this topic helpful?