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}]
Answer
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:
Comments
Post a Comment