0
$\begingroup$

I am attempting to animate my parametric plot, but am having difficulties. I tried simply wrapping the plot code with an Animate[expression,{t,0,5}], but that hasn't worked, and I simply get a red animation screen. Any suggestions? Could someone tell me what is going wrong?

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, θ'[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 -> y, PlotRange -> {10}]
$\endgroup$
5
  • $\begingroup$ Animate with respect to which variable? $\endgroup$ Jun 2, 2015 at 22:33
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) 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, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Jun 2, 2015 at 22:47
  • 1
    $\begingroup$ Do yourself a favor and forget using subscripted symbols until you master Mathematica really well $\endgroup$ Jun 2, 2015 at 22:50
  • $\begingroup$ I am trying to animate with respect to t. $\endgroup$
    – Jon
    Jun 2, 2015 at 23:01
  • $\begingroup$ please do not use first UpperCase for variables, symbols and function names. If you must use single UpperCase letter, add a number to it. Say R0 and D0 and such. $\endgroup$
    – Nasser
    Jun 3, 2015 at 4:24

1 Answer 1

5
$\begingroup$

First note that there are two errors in the ParametricPlot: (1) an error in the syntax of PlotRange, and (2) your time domain {t,0,5} goes outside the domain of the InterpolatingFunction. Be consistent with your choices of time domain by continuing to use $t_0$ and $t_f$, as shown below.

Second, as noted in the comments, avoid subscripts. I would use t0 in place of Subscript[t,0], although t[0] is another option.

Finally, note that because of the nature of the solution to the differential equation, $\theta(t)$ is oscillatory, and so the solution will trace out only a piece of the spiral you have plotted. I recommend plotting $\theta(t)$ directly to see this behavior.

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.

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, θ'[0] == 0}, θ, {t, t0, tf}];

Animate[ParametricPlot[{(l - r θ) Cos[θ] + r Sin[θ], r Cos[θ] - (l - r θ) Sin[θ]}, {θ, 0, -20}, Epilog -> {PointSize -> 0.015, Evaluate[Point[{(l - r θ[t]) Cos[θ[t]] + r Sin[θ[t]],r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]}] /. soln[[1]]]}], {t, t0, tf}]

Here is the result of the animation:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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