Plotting the solution of a vector stochastic differential equation - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-23T10:41:18Z https://mathematica.stackexchange.com/feeds/question/15701 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/15701 16 Plotting the solution of a vector stochastic differential equation David https://mathematica.stackexchange.com/users/103 2012-12-04T16:12:01Z 2012-12-04T19:01:43Z <p>I have a vector stochastic differential equation,</p> <p>$$\mathrm dq = p\,\mathrm dt\qquad q(0)=0$$ $$\mathrm dp = (-q -p)\mathrm dt+\mathrm dW\qquad p(0)=10$$</p> <p>This can be entered to give me the process describing <strong>either</strong> p or q, using</p> <pre><code>proc = ItoProcess[ {{p[t], -p[t]-q[t]}, {{0}, {1}}, XXX[t]}, {{q, p}, {0, 10}}, {t,0} ] </code></pre> <p>where <code>XXX</code> is either <code>q</code> or <code>p</code>. The solution can be plotted using the usual method (here for <code>p</code>) of</p> <pre><code>ListLinePlot@RandomFunction[proc, {0, 10, .02}, 10] </code></pre> <blockquote> <p><img src="https://i.stack.imgur.com/bBTbp.png" alt="enter image description here"></p> </blockquote> <p>However, the situation is more difficult if I want to extract <strong>both</strong> <code>q</code> and <code>p</code>, as for each simulation it will give me a list of the type (obtained using <code>Normal</code>, and by setting <code>XXX[t]</code> to <code>{q[t], p[t]}</code> in the <code>ItoProcess</code>)</p> <pre><code>{{{t0, {q[t0], p[t0]}}, {t1, {q[t1], p[t1]}}, ...} </code></pre> <p>i.e. the times aren't properly distributed over the p/q, and as a consequence I'm having a hard time finding a good way of getting this into a plottable form.</p> <p>So the questions are:</p> <ol> <li>Is there a nice way of getting all components out of a vector stochastic differential equation to plot them alongside each other?</li> <li>If there's none, what's the right hacky approach? Fiddling with <code>Transpose</code> and <code>Flatten</code>?</li> </ol> https://mathematica.stackexchange.com/questions/15701/-/15707#15707 5 Answer by Rojo for Plotting the solution of a vector stochastic differential equation Rojo https://mathematica.stackexchange.com/users/109 2012-12-04T17:14:35Z 2012-12-04T17:14:35Z <p>Please confirm if this is what you were looking for</p> <pre><code>proc = ItoProcess[{{p[t], -p[t] - q[t]}, {{0}, {1}}, {q[t], p[t]}}, {{q, p}, {0, 10}}, {t, 0}]; data = RandomFunction[proc, {0, 10, 0.02}, 10]; </code></pre> <p>You could do</p> <pre><code>Plot[Through@data["PathFunction", All][t], {t, 0, 10}, Evaluated -&gt; True] </code></pre> <p><img src="https://i.stack.imgur.com/TvrcW.png" alt="Mathematica graphics"></p> https://mathematica.stackexchange.com/questions/15701/-/15708#15708 14 Answer by Sasha for Plotting the solution of a vector stochastic differential equation Sasha https://mathematica.stackexchange.com/users/38 2012-12-04T17:16:10Z 2012-12-04T17:16:10Z <p>You could use <code>"PathComponents"</code> property of <code>TemporalData</code> to split the vector-valued temporal data into the list of <code>TemporalData</code> objects and plot those:</p> <pre><code>proc = ItoProcess[{{p[t], -p[t] - q[t]}, {{0}, {1}}}, {{q, p}, {0, 10}}, {t, 0}]; td = RandomFunction[proc, {0., 10., 0.02}, 10]; td["PathComponents"] </code></pre> <p><img src="https://i.stack.imgur.com/Fmx2D.png" alt="enter image description here"></p> https://mathematica.stackexchange.com/questions/15701/-/15712#15712 2 Answer by Vitaliy Kaurov for Plotting the solution of a vector stochastic differential equation Vitaliy Kaurov https://mathematica.stackexchange.com/users/13 2012-12-04T18:04:19Z 2012-12-04T19:01:43Z <p>Another way to visualize this is in the parametric phase space:</p> <pre><code>ListLinePlot[td[[2, 1]], Frame -&gt; True, AspectRatio -&gt; 1, PlotRange -&gt; All] </code></pre> <p><img src="https://i.stack.imgur.com/T99S0.png" alt="enter image description here"></p> <p><strong>---------- Comment reponse ----------</strong></p> <p>We can check the structure of underlying expression with <strong>InputForm</strong> and then it is straightforward to use <strong>Part</strong> to extract the sub-expressions:</p> <p><img src="https://i.stack.imgur.com/ciB6o.png" alt="enter image description here"></p>