# Recurrence relation, DiscretePlot with a variable initial value

Ok, so I'm dealing with a recursive function (you can see it here on MathExchange as I have problems also on the analytic resolution) that I'm trying to solve numerically. The relation is

$$\begin{cases} x_{n+1} = e^{-x^2_{n}}\\ x_0 = a\in\mathbb{R} \end{cases}$$

So I have $a$ that could be any real. Since I would like to visualise how the function goes I made this code:

a = 1;
G[0] = a;
G[y_] := Exp[-G[y - 1]^2]
DiscretePlot[G[y], {y, 0, 30}, PlotRange -> {0.2, 1}]


with the test value $a = 1$, which produce this output:

Now, since $a$ is not 1 in general, I would like to make $a$ become a variable parameter to change and make something like Manipulate[] in order to see graphically how the relation changes by changing $a$. I tried

G[0] = a;
G[y_] := Exp[-G[y - 1]^2]
Manipulate[DiscretePlot[G[y], {y, 0, 30}, PlotRange -> {0, 1}], {a, 0, 10}]


Obviously it didn't work at all. Any advice?

ClearAll[G, a]
G[0] = a;
G[y_] := Exp[-G[y - 1]^2]

Manipulate[DiscretePlot[With[{a = a}, Evaluate@G[y]], {y, 0, 30},
PlotRange -> {0, 1}], {a, 0, 10}]


• I don't know why but your solution is not working, actually by changing $a$ nothing happens. – opisthofulax Jul 6 '17 at 18:47
• @opisthofulax Replace first line by ClearAll[G, a] i think will make it work – Coolwater Jul 6 '17 at 18:50
• Yep, perfectly, thanks for your answer! If I may ask , do you know a say to plot this manipulate beside another manipulate (which this time is not a DiscretePlot , just a normal plot)? I tried with Table and Show, with not much success... – opisthofulax Jul 6 '17 at 18:53
• @opisthofulax, something like this: Manipulate[ Row[{DiscretePlot[With[{a = a}, Evaluate@G[y]], {y, 0, 30}, PlotRange -> {0, 1}, ImageSize -> 200], Plot[Sin[x], {x, 0, Pi}, ImageSize -> 200]}, Spacer[10]], {a, 0, 10}]? – kglr Jul 6 '17 at 18:56
• Exactly what I was looking for. Best answer for you! – opisthofulax Jul 6 '17 at 19:01

You can include it in the definition:

G[0, a_] := a;
G[y_, a_] := Exp[-G[y - 1, a]^2]
Manipulate[DiscretePlot[G[y, a], {y, 0, 30}, PlotRange -> {0.2, 1}], {a, 1, 10}]

• Smart solution! – opisthofulax Jul 6 '17 at 18:47

RecurrenceTable might be used:

Manipulate[ListPlot[Transpose[{Range[0, 30],
RecurrenceTable[{g[y + 1] == Exp[-g[y]^2], g[0] == a}, g, {y, 0, 30}]}],
Filling -> Axis, PlotRange -> {0, 1}], {a, 0, 3}]

• Actually it is not given the proper result... Thanks anyway. – opisthofulax Jul 6 '17 at 18:53