I am trying to simulate a simple 2d Ito SDE (randomly perturbed Hamiltonian system). Below is the code.

proc = ItoProcess[{\[DifferentialD]x[t] == 
 v[t] \[DifferentialD]t, 
 \[DifferentialD]v[t] == -x[t] ((x[t])^2 - 1) \[DifferentialD]t + 
  Sqrt[2*0.01] \[DifferentialD]w[t]}
  , {x[t],v[t]}, {{x, v}, {0.9, 0.7}}, t, w \[Distributed] WienerProcess[]];

Question: I would like to plot the output (x,v) in a 2d-plane. How does one do this?

I tried to use the following

path = RandomFunction[proc, {0., 15, 0.05}, 1]

but I do not understand how to generate a 2d object. I am more interested in looking at the full trajectory in the phase space (x,v-space) rather than evolution.

I am extremely grateful for any advice and help. I am new to these ideas and therefore apologise if this question is too stupid.

PS. The actual aim is to superimpose this random trajectory onto the level sets of the Hamiltonian $H(x,v)=0.5\, v^2+0.25\, (x^2-1)^2$ which drives the deterministic part of the SDE.

  • $\begingroup$ ListPlot[path] ? $\endgroup$ – Sektor May 9 '15 at 16:06
  • 1
    $\begingroup$ But that plots both x and v separately. I want to plot the coordinate (x,v) in a plane. $\endgroup$ – UPS May 9 '15 at 16:12
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – Mahdi May 9 '15 at 17:15

You need to extract data from path=RandomFunction using part. The following gives {x,v} list:

pts = path[[2, 1, 1]]

Now you can plot pts in the plane:

ListPlot[pts, Frame -> True, FrameLabel -> {"x", "v"}]

enter image description here

  • $\begingroup$ Yes this works perfectly. Thank you very much. Just one question. What kind of data is [[2,1,1]] extracting exactly, or more specifically in what order? $\endgroup$ – UPS May 9 '15 at 17:23
  • $\begingroup$ My pleasure! Assume path is a multidimensional matrix. You need to extract the right element form the matrix. Now if you try these one by one path[[2]], path[[2,1]] and path[[2,1,1]], you see how data points are extracted from path. $\endgroup$ – Mahdi May 9 '15 at 17:27

Since path is a TemporalData object, you can also make use of its various "Properties"

proc = ItoProcess[{\[DifferentialD]x[t] == 
        v[t] \[DifferentialD]t, \[DifferentialD]v[t] == -x[t] ((x[t])^2 - 1) 
        \[DifferentialD]t + Sqrt[2*0.01] \[DifferentialD]w[t]}, {x[t], 
    v[t]}, {{x, v}, {0.9, 0.7}}, t, w \[Distributed] WienerProcess[]];

path = RandomFunction[proc, {0., 15, 0.05}, 1];


{"Part", "Path", "PathComponents", "PathCount", "PathFunction", "PathFunctions", "PathLengths", "Paths", "PathStates", "PathTimes", "Properties", "SliceData", "SliceDistribution", "StateDimensions", "States", "Times"}


Mathematica graphics

ListLinePlot[path["States"], Mesh -> All]

Mathematica graphics

ParametricPlot[path["PathFunction"]@x, {x, 0, Max@path["Times"]}, 
  AspectRatio -> 1/GoldenRatio]

Mathematica graphics

ListPlot[path["PathComponents"]] (* or ListPlot[path] *)

Mathematica graphics

Plot[path["PathFunction"]@x, {x, 0, Max@path["Times"]}]

Mathematica graphics

  • $\begingroup$ Very detailed. Thank you very much. Helps a lot. $\endgroup$ – UPS May 9 '15 at 19:37
  • $\begingroup$ @UPS, my pleasure. Welcome to mma.se. $\endgroup$ – kglr May 9 '15 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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