3
$\begingroup$

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[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:

enter image description here

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?

$\endgroup$

3 Answers 3

3
$\begingroup$
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}]

enter image description here

$\endgroup$
5
  • $\begingroup$ I don't know why but your solution is not working, actually by changing $a$ nothing happens. $\endgroup$ Jul 6, 2017 at 18:47
  • 2
    $\begingroup$ @opisthofulax Replace first line by ClearAll[G, a] i think will make it work $\endgroup$
    – Coolwater
    Jul 6, 2017 at 18:50
  • $\begingroup$ 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... $\endgroup$ Jul 6, 2017 at 18:53
  • 1
    $\begingroup$ @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}]? $\endgroup$
    – kglr
    Jul 6, 2017 at 18:56
  • $\begingroup$ Exactly what I was looking for. Best answer for you! $\endgroup$ Jul 6, 2017 at 19:01
2
$\begingroup$

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}]
$\endgroup$
1
  • $\begingroup$ Smart solution! $\endgroup$ Jul 6, 2017 at 18:47
0
$\begingroup$

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}]
$\endgroup$
1
  • $\begingroup$ Actually it is not given the proper result... Thanks anyway. $\endgroup$ Jul 6, 2017 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.