Originally Posted by

**bkarpuz** One may wish to learn the solution.

I have coded the following and it works.

Code:

n = 2;
\[Phi][t_] = t;
xmax = MaxValue[{\[Phi][t], t >= -1, t <= 0}, t];
xmin = MinValue[{\[Phi][t], t >= -1, t <= 0}, t];
x = Table[ 0, {i, 1, n + 1}];
x[[1]] = \[Phi][t];
For[i = 2, i <= n + 1, i++,
x[[i]] = Simplify[(ReplaceAll[x[[i - 1]], t -> (t - 1)]
+ 1)^2];
xmax = Max[{xmax, MaxValue[{x[[i]], t >= i - 2,
t <= i - 1}, t]}];
xmin = Min[{xmin, MinValue[{x[[i]], t >= i - 2,
t <= i - 1}, t]}];
]
Show[Table[
Plot[x[[i]], {t, i - 2, i - 1},
PlotRange -> {{-1, n}, {xmin, xmax}}], {i, 1, n + 1}]]

I have another question.

How can I build a function for this?

I mean I will only send

and

to the function and get the output figure?

Let me answer this one first. Not sure about the other one you asked. In the code below, I convertet your code to a function called myFunction and passed to it a value of n as well as a function f[t_]:=t and then used Show[myFunction[2,f]]:

Code:

f[t_] := t;
myFunction[n_, myf_] := Module[{xmax, xmin, x, i},
xmax = MaxValue[{myf[t], t >= -1, t <= 0}, t];
xmin = MinValue[{myf[t], t >= -1, t <= 0}, t];
x = Table[0, {i, 1, n + 1}];
x[[1]] = myf[t];
For[i = 2, i <= n + 1, i++,
x[[i]] = Simplify[(ReplaceAll[x[[i - 1]], t -> (t - 1)] + 1)^2];
xmax = Max[{xmax, MaxValue[{x[[i]], t >= i - 2, t <= i - 1}, t]}];
xmin = Min[{xmin, MinValue[{x[[i]], t >= i - 2, t <= i - 1}, t]}];
];
Table[Plot[x[[i]], {t, i - 2, i - 1},
PlotRange -> {{-1, n}, {xmin, xmax}}], {i, 1, n + 1}]
];
Show[myFunction[2, f]]