# Function composition of function of several variables

Suppose I have the following function g[{x_, y_}, c0_, b_] := {x^2 + c0 - b*y, x} where b and c0 are parameter values.

Suppose we fix the values of c0 and b, say, g[{x_, y_}, -5, 1.2]. Is there a way to get the $$nth$$ composition of g with itself? So a function say G[{x_,y_},n,-5,1.2] which gives g[{x, y}, -5, 1.2] @* g[{x, y}, -5, 1.2] @* ... @* g[{x, y}, -5, 1.2] $$n$$ times? I would like to then use this to find period $$n$$ points using NSolve so I think this is the form I would require.

You can do something like:

gcomp[n_Integer] := Composition @@ ConstantArray[g[#, -5, 1.2] &, n]


Which you can then use as:

gcomp[3][{0, 0}]


Or perhaps even better:

gcomp[n_Integer, c0_, b_] := Composition @@ ConstantArray[g[#, c0, b] &, n];
gcomp[3, -5, 1.2][{0, 0}]

• This is wonderful thanks!
– math
Nov 17, 2020 at 12:07
n=3;
g[{x_, y_}, c0_, b_] := {x^2 + c0 - b*y, x};
Nest[Function[t, g[t, -5, 1.2]], {x0, y0}, n]

• n = 3; g[{x_, y_}, c0_, b_] := {x^2 + c0 - b*y, x}; Nest[g[#, -5, 1.2] &, {x0, y0}, n] Nov 17, 2020 at 12:00