Animating a parametric plot - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-11-12T21:04:59Z https://mathematica.stackexchange.com/feeds/question/85032 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/85032 0 Animating a parametric plot Jon https://mathematica.stackexchange.com/users/29919 2015-06-02T22:29:37Z 2019-01-28T17:49:44Z <p>I am attempting to animate my parametric plot, but am having difficulties. I tried simply wrapping the plot code with an <code>Animate[expression,{t,0,5}]</code>, but that hasn't worked, and I simply get a red animation screen. Any suggestions? Could someone tell me what is going wrong? </p> <pre><code>R= 2; l = 6; m = 9; g = -9.81; Subscript[t, 0] = 0; Subscript[t, f] = 1; x[t_] = (l - R θ[t]) Cos[θ[t]] + R Sin[θ[t]]; y[t_] = R Cos[θ[t]] - (l - R θ[t]) Sin[θ[t]]; T = (1/2) m ((x'[t])^2 + (y'[t])^2); U = m g (R Cos[θ[t]] - (l - R θ[t]) Sin[θ[t]]); L = T - U; EL[t_] = (D[L, θ[t]] - D[ D[L, θ'[t]], t]) // FullSimplify; soln = NDSolve[{EL[t] == 0, θ == 0, θ' == 0}, θ, {t, Subscript[t, 0], Subscript[t, f]}]; ParametricPlot[ Evaluate[{(l - R θ[t]) Cos[θ[t]] + R Sin[θ[t]], R Cos[θ[t]] - (l - R θ[t]) Sin[θ[t]]} /. soln], {t, 0, 5}, AxesLabel -&gt; y, PlotRange -&gt; {10}] </code></pre> https://mathematica.stackexchange.com/questions/85032/-/85046#85046 5 Answer by march for Animating a parametric plot march https://mathematica.stackexchange.com/users/29734 2015-06-03T04:17:11Z 2019-01-28T17:49:44Z <p>First note that there are two errors in the <code>ParametricPlot</code>: (1) an error in the syntax of <code>PlotRange</code>, and (2) your time domain <code>{t,0,5}</code> goes outside the domain of the <code>InterpolatingFunction</code>. Be consistent with your choices of time domain by continuing to use <span class="math-container">$t_0$</span> and <span class="math-container">$t_f$</span>, as shown below.</p> <p>Second, as noted in the comments, avoid subscripts. I would use <code>t0</code> in place of <code>Subscript[t,0]</code>, although <code>t</code> is another option.</p> <p>Finally, note that because of the nature of the solution to the differential equation, <span class="math-container">$\theta(t)$</span> is oscillatory, and so the solution will trace out only a piece of the spiral you have plotted. I recommend plotting <span class="math-container">$\theta(t)$</span> directly to see this behavior.</p> <p>Here is working code, with minimal changes that make it work, along with an animation where a point traces out the curve according to the solution of the differential equation.</p> <pre><code>r = 2; l = 6; m = 9; g = -9.81; t0 = 0; tf = 6.67; x[t_] = (l - r θ[t]) Cos[θ[t]] + r Sin[θ[t]]; y[t_] = r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]; kE = (1/2) m ((x'[t])^2 + (y'[t])^2); pE = m g (r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]); lagrangian = kE - pE; eL[t_] = (D[lagrangian, θ[t]] - D[D[lagrangian, θ'[t]], t]) //FullSimplify; soln = NDSolve[{eL[t] == 0, θ == 0, θ' == 0}, θ, {t, t0, tf}]; Animate[ParametricPlot[{(l - r θ) Cos[θ] + r Sin[θ], r Cos[θ] - (l - r θ) Sin[θ]}, {θ, 0, -20}, Epilog -&gt; {PointSize -&gt; 0.015, Evaluate[Point[{(l - r θ[t]) Cos[θ[t]] + r Sin[θ[t]],r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]}] /. soln[]]}], {t, t0, tf}] </code></pre> <p>Here is the result of the animation:</p> <p><img src="https://i.stack.imgur.com/0Ze60.gif" alt="enter image description here"></p>