# Animate these 2D plots?

Posted 6 days ago
252 Views
|
8 Replies
|
3 Total Likes
|
 Consider the following code: z1 = {-R*W*Sin[W*t] + l'[t]*Sin[\[Phi][t]] + l[t]*(\[Phi]'[t])*Cos[\[Phi][t]], R*W*Cos[W*t] - l'[t]*Cos[\[Phi][t]] + l[t]*(\[Phi]'[t])*Sin[\[Phi][t]]}; V = m*g*(R*Sin[W*t] - l[t]*Cos[\[Phi][t]]) + 1/2*k*(l[t] - l0)^2; T = 1/2*m*z1.z1; Lagrange = T - V; eqs = D[D[Lagrange, \[Phi]'[t]], t] - D[Lagrange, \[Phi][t]]; eqs2 = D[D[Lagrange, l'[t]], t] - D[Lagrange, l[t]]; g = 9.7; m = 1; l0 = 1; k = 1000; R = 2; W = Pi/2; sol = NDSolveValue[{eqs == 0, eqs2 == 0, l[0] == l0, l'[0] == 0, Derivative[1][\[Phi]][0] == 0, \[Phi][0] == 0}, {l[t], \[Phi][ t]}, {t, 0, 20}] {Plot[sol.{1, 0}, {t, 0, 5}, AxesLabel -> {"t", "l"}], Plot[sol.{0, 1}, {t, 0, 5}, AxesLabel -> {"t", "\[Phi]"}]} 
8 Replies
Sort By:
Posted 5 days ago
 Try Plot[Evaluate[#[[2]] & /@ Flatten[sol] /. t -> tt], {tt, 0, 5}, PlotStyle -> {Red, Blue}] 
Posted 4 days ago
 Dear Ã–mer,I don't know what you really want to do, what the physical situation is you want to describe and if your equations are correct.Anyhow, what about this? Is it this what you want to see? z1 = {-R*W*Sin[W*t] + l'[t]*Sin[\[Phi][t]] + l[t]*(\[Phi]'[t])*Cos[\[Phi][t]], R*W*Cos[W*t] - l'[t]*Cos[\[Phi][t]] + l[t]*(\[Phi]'[t])*Sin[\[Phi][t]]}; V = m*g*(R*Sin[W*t] - l[t]*Cos[\[Phi][t]]) + 1/2*k*(l[t] - l0)^2; T = 1/2*m*z1.z1; Lagrange = T - V; eqs = D[D[Lagrange, \[Phi]'[t]], t] - D[Lagrange, \[Phi][t]]; eqs2 = D[D[Lagrange, l'[t]], t] - D[Lagrange, l[t]]; g = 9.7; m = 1; l0 = 1; k = 1000; R = 2; W = Pi/2; sol = NDSolve[{eqs == 0, eqs2 == 0, l[0] == l0, l'[0] == 0, Derivative[1][\[Phi]][0] == 0, \[Phi][0] == 0}, {l[t], \[Phi][ t]}, {t, 0, 20}]; p1 = R {Cos[W t], Sin[W t]}; z1a = z1 /. Flatten[sol /. a_[t] -> a]; Animate[Graphics[{Circle[{0, 0}, R], PointSize[.05], Black, Point[p1 /. t -> tt], Red, Point[z1a /. t -> tt], Blue, Line[{p1, z1a} /. t -> tt]}, Axes -> True, PlotRange -> {{-4, 4}, {-4, 4}}], {tt, 0, 20}] 
Posted 4 days ago
 Is it this what you want to see? I am afraid that no. you wrote that z1 is the derivative of your position-vector. So xx = \[Integral]z1 \[DifferentialD]t and p1 = R {Cos[W t], Sin[W t]}; xxa = xx /. Flatten[sol /. a_[t] -> a]; Animate[Graphics[{Circle[{0, 0}, R], PointSize[.05], Black, Point[p1 /. t -> tt], Red, Point[xxa /. t -> tt], Blue, Line[{p1, xxa} /. t -> tt]}, Axes -> True, PlotRange -> {{-4, 4}, {-4, 4}}], {tt, 0, 20}] is perhaps more what you want to see.
Posted 5 days ago
 I mean like this double-pendulum animation here.How can I make like this for my equation?https://mathematica.stackexchange.com/questions/48059/animation-of-double-pendulum
Posted 5 days ago
 You could try this, I hope it helps. z1 = {-R*W*Sin[W*t] + l'[t]*Sin[\[Phi][t]] + l[t]*(\[Phi]'[t])*Cos[\[Phi][t]], R*W*Cos[W*t] - l'[t]*Cos[\[Phi][t]] + l[t]*(\[Phi]'[t])*Sin[\[Phi][t]]}; V = m*g*(R*Sin[W*t] - l[t]*Cos[\[Phi][t]]) + 1/2*k*(l[t] - l0)^2; T = 1/2*m*z1.z1; Lagrange = T - V; eqs = D[D[Lagrange, \[Phi]'[t]], t] - D[Lagrange, \[Phi][t]]; eqs2 = D[D[Lagrange, l'[t]], t] - D[Lagrange, l[t]]; g = 9.7; m = 1; l0 = 1; k = 1000; R = 2; W = Pi/2; sol = NDSolve[{eqs == 0, eqs2 == 0, l[0] == l0, l'[0] == 0, Derivative[1][\[Phi]][0] == 0, \[Phi][0] == 0}, {l[t], \[Phi][ t]}, {t, 0, 20}]; z1a = z1 /. Flatten[sol /. a_[t] -> a]; Animate[ Graphics[{Red, PointSize[.05], Point[z1a /. t -> tt]}, Axes -> True, PlotRange -> {{-4, 4}, {-4, 4}}], {tt, 0, 20}] 
Posted 5 days ago
 Or did you mean something like this? ParametricPlot[z1a /. t -> tt, {tt, 0, 3}, Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}}]