# 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{equation} \begin{cases} x_{n+1} = e^{-x^2_{n}}\\ x_0 = a\in\mathbb{R} \end{cases} \end{equation}

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 = 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 = 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 = 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. Jul 6, 2017 at 18:47
• @opisthofulax Replace first line by ClearAll[G, a] i think will make it work Jul 6, 2017 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... Jul 6, 2017 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], {a, 0, 10}]?
– kglr
Jul 6, 2017 at 18:56
• Exactly what I was looking for. Best answer for you! Jul 6, 2017 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! Jul 6, 2017 at 18:47

RecurrenceTable might be used:

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

• Actually it is not given the proper result... Thanks anyway. Jul 6, 2017 at 18:53