# Plotting two recursive functions

I'm trying to plot two recursive functions (p and θ) on a map. So far I have:

θ0 = Pi/2;
p0 = 0;
α = 0.1;
β = 1;

θ[j_] := θ[j] = θ[j - 1] + β*p[j - 1];
p[j_] := p[j] =
p[j - 1] - α*Sin[θ[j - 1] + β*p[j - 1]];
θ = θ0;
p = p0;


How can I plot p[j] against θ[j] for 0 <= j <= 100?

I think you are looking for DiscretePlot:

DiscretePlot[{θ[j], p[j]}, {j, 0, 100}] Or perhaps you want something like this?:

ListPlot @ Table[{θ[j], p[j]}, {j, 0, 100}] Another method is to use ParametricPlot after sufficiently coercing the input, e.g.:

f[x_?NumericQ] := {θ[#], p[#]} & @ Round @ x

ParametricPlot[f[j], {j, 0, 100}] (Aspect ratio may be controlled with the AspectRatio option.)

• that plots p and θ by j. I need to plot p by θ (for every matching j) as it if were a phase space – Geo Oct 18 '14 at 22:39
• @Geo You mean you want p on one axis and θ on the other? – Mr.Wizard Oct 18 '14 at 22:41
• yeah. sorry my not being so clear on the question. – Geo Oct 18 '14 at 22:43
• @Geo Please see update. – Mr.Wizard Oct 18 '14 at 22:43
• ahh that's it. Thank you sir. – Geo Oct 18 '14 at 22:44

A proposal using Functional paradigm to avoid recursive functions.

data=
With[{α = .1, β = 1},
NestList[
{#[] + β #[], #[] - α Sin[#[] + β #[]]} &,
{Pi/2, 0}, 100]];

ListPlot[data] • Although this doesn't directly answer the question it does show a good technique; NestList is often faster and simpler than recursion in Mathematica. By the way this can also be written: With[{α = .1, β = 1}, NestList[{# + β #2, #2 - α Sin[# + β #2]} & @@ # &, {Pi/2, 0}, 100]] – Mr.Wizard Oct 19 '14 at 2:29
• @Mr.Wizard,+1, your solution is indeed I need! I am alway writing the code: With[{α = .1, β = 1}, NestList[{# + β #2, #2 - α Sin[# + β #2]} & , [Pi/2, 0], 100]] before. Thanks sir! – xyz Oct 19 '14 at 2:32
• You're welcome. Another method you might like: With[{α = .1, β = 1}, NestList[# /. {x_, y_} :> {x + β y, y - α Sin[x + β y]} &, {Pi/2, 0}, 100]] as described here: (8399). This can be more readable than an excessive number of #* parameters. – Mr.Wizard Oct 19 '14 at 2:50
• that's interesting. I will try using this for plotting the results for different initial conditions on the same graph. thanks – Geo Oct 20 '14 at 12:43
• @Geo,see [here]( mathematica.stackexchange.com/questions/61050/…)，my answer is at last. – xyz Oct 20 '14 at 13:15