Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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] = θ0;
p[0] = p0;

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

share|improve this question

2 Answers 2

I think you are looking for DiscretePlot:

DiscretePlot[{θ[j], p[j]}, {j, 0, 100}]

enter image description here

Or perhaps you want something like this?:

ListPlot @ Table[{θ[j], p[j]}, {j, 0, 100}]

enter image description here

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}]

enter image description here

(Aspect ratio may be controlled with the AspectRatio option.)

share|improve this answer
    
that plots p and θ by j. I need to plot p by θ (for every matching j) as it if were a phase space –  Geo yesterday
    
@Geo You mean you want p on one axis and θ on the other? –  Mr.Wizard yesterday
    
yeah. sorry my not being so clear on the question. –  Geo 23 hours ago
    
@Geo Please see update. –  Mr.Wizard 23 hours ago
    
ahh that's it. Thank you sir. –  Geo 23 hours ago

A proposal using Functional paradigm to avoid recursive functions.

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

ListPlot[data]

enter image description here

share|improve this answer
1  
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 20 hours ago
    
@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! –  ShutaoTang 20 hours ago
1  
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 19 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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