1
$\begingroup$

I am using a Wolfram demonstration that shows Newton’s Second Law: https://demonstrations.wolfram.com/TwoMassesOnInclinedPlaneWithPulley/

I am not too familiar with creating animations and I was hoping my question will help me learn more. My question is

Is it possible to create a tracker for this demonstration/animation that will plot the velocity of one of the blocks over time or the displacement over time.

What would I need to add to the source code so that I can create a plot of the velocity over time as the simulation/animation runs. Could the points on the plot be created infinitesimally or incrementally as the blocks are moving. Could the plot be created under the animation.

I am not too sure if this is possible in Mathematica, but I would really hope to see how to accomplish this if possible.

Thank you!


EDIT: I tried applying the first answer to my notebook which has some modification:

Manipulate[
 With[{a = 
    If[m2 > m1 (\[Mu] Cos[\[Theta]] + Sin[\[Theta]]), (
     9.8 (m2 - \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(
     m1 + m2), (
     9.8 (m2 + \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(m1 + m2)],
    v = If[m2 > m1 (\[Mu] Cos[\[Theta]] + Sin[\[Theta]]), (
     9.8 t (m2 - \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(
     m1 + m2), (
     9.8 t (m2 + \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(
     m1 + m2)], 
   x = If[m2 > m1 (\[Mu] Cos[\[Theta]] + Sin[\[Theta]]), (
     9.8 t^2 (m2 - \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(
     2 (m1 + m2)), (
     9.8 t^2 (m2 + \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(
     2 (m1 + m2))], 
   T = If[m2 > m1 (\[Mu] Cos[\[Theta]] + Sin[\[Theta]]), (
     9.8 m1 m2 (1 + \[Mu] Cos[\[Theta]] + Sin[\[Theta]]))/(m1 + m2), (
     9.8 m1 m2 (1 - \[Mu] Cos[\[Theta]] + Sin[\[Theta]]))/(m1 + m2)]},
   With[{t = 
     Which[-.75 <= a t <= 1.75, t, a t < -.75, -1/a, True, 1.75/a]}, 
   Overlay[{Graphics[{EdgeForm[RGBColor[0.5, 0.5, 0.5]], 
       Rotate[
        Line[{{-1.75 + a t, 3.25}, {.4, 3.25}}], \[Theta], {0, 3}], 
       Line[{{.25, 3.4}, {.25, 2. - a t}}], 
       Rotate[{Line[{{0, 3}, {0.25, 3.25}}], 
         Disk[{0.25, 3.25}, .25]}, \[Theta]/2, {0, 3}], Gray, 
       Polygon[{{0, 0}, {0, 3}, {3 Cos[\[Theta] + \[Pi]], 
          3 Sin[\[Theta] + \[Pi]] + 3}, {3 Cos[\[Theta] + \[Pi]], 
          0}}], RGBColor[0.06, 0.23, 0.27], 
       Rotate[Rectangle[{-2.25 + a t, 3}, {-1.75 + a t, 
          3.5}], \[Theta], {0, 3}], RGBColor[0.08, 0.2, 0.08], 
       Rectangle[{0, 2 - a t}, {.5, 1.5 - a t}]},
      ImageSize -> 400, PlotRange -> {{-3.5, 1}, {-.5, 4}}, 
      PlotLabel -> 
       Row[{Style["a", Italic], " = ", NumberForm[a, {3, 2}], 
         Style[" m/\!\(\*SuperscriptBox[\(s\), \(2\)]\)", 
          SingleLetterItalics -> False], Spacer[10], "|", Spacer[10], 
         Style["v", Italic], " = ", NumberForm[v, {3, 2}], 
         Style[" m/s", SingleLetterItalics -> False], Spacer[10], "|",
          Spacer[10], Style["x", Italic], " = ", 
         NumberForm[x, {3, 2}], 
         Style[" m", SingleLetterItalics -> False], Spacer[10], "|", 
         Spacer[10], Style["T", Italic], " = ", NumberForm[T, {3, 2}],
          " N"}]], 
     Plot[a x, {x, 0, t}, ImageSize -> 200, 
      PlotRange -> {{0, Pi/2}, {-2, 3.}}]}, 
    Alignment -> {Left, 0.8}]]], {{t, 0., Style["t", Italic]}, 
  0, \[Pi]/6, .01, ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{\[Theta], 0}, 0, 0, .01, 
  ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{m1, .5, 
   Text@Subscript[Style["m", Italic], 1]}, .25, .75, .01, 
  ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{m2, .5, 
   Text@Subscript[Style["m", Italic], 2]}, .25, .75, .01, 
  ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{\[Mu], .1}, .0, .0 .2, .01, 
  ImageSize -> Tiny, Appearance -> "Labeled"}, 
 ControlPlacement -> Left]

But, this didn't work. It is just pink and not plotting anything. What did I do wrong?

$\endgroup$

1 Answer 1

3
$\begingroup$

Here is an example with Overlay[]:

Manipulate[
 With[{a = 
    If[m2 > m1 (\[Mu] Cos[\[Theta]] + Sin[\[Theta]]), (
     9.8 (m2 - \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(
     m1 + m2), (
     9.8 (m2 + \[Mu] m1 Cos[\[Theta]] - m1 Sin[\[Theta]]))/(m1 + m2)],
    T = If[m2 > m1 (\[Mu] Cos[\[Theta]] + Sin[\[Theta]]), (
     9.8 m1 m2 (1 + \[Mu] Cos[\[Theta]] + Sin[\[Theta]]))/(m1 + m2), (
     9.8 m1 m2 (1 - \[Mu] Cos[\[Theta]] + Sin[\[Theta]]))/(m1 + m2)]},
   With[{t = 
     Which[-.75 <= a t <= 1.75, t, a t < -.75, -1/a, True, 1.75/a]}, 
   Overlay[{Graphics[{EdgeForm[Black], 
       Rotate[Line[{{-1.75 + a t, 3.25}, {.4, 3.25}}], \[Theta], {0, 
         3}], Line[{{.25, 3.4}, {.25, 2. - a t}}], 
       Rotate[{Line[{{0, 3}, {0.25, 3.25}}], 
         Disk[{0.25, 3.25}, .25]}, \[Theta]/2, {0, 3}], Cyan, 
       Polygon[{{0, 0}, {0, 3}, {3 Cos[\[Theta] + \[Pi]], 
          3 Sin[\[Theta] + \[Pi]] + 3}, {3 Cos[\[Theta] + \[Pi]], 
          0}}], Brown, 
       Rotate[Rectangle[{-2.25 + a t, 3}, {-1.75 + a t, 
          3.5}], \[Theta], {0, 3}], Darker@Green, 
       Rectangle[{0, 2 - a t}, {.5, 1.5 - a t}]},
      
      ImageSize -> 400, PlotRange -> {{-3.5, 1}, {-.5, 4}}, 
      PlotLabel -> 
       Row[{Style["a", Italic], " = ", NumberForm[a, {3, 2}],
         Style[" m/\!\(\*SuperscriptBox[\(s\), \(2\)]\)", 
          SingleLetterItalics -> False], Spacer[10], "|", Spacer[10], 
         Style["T", Italic], " = ", NumberForm[T, {3, 2}], " N"}]], 
     Plot[a x, {x, 0, t}, ImageSize -> 200, 
      PlotRange -> {{0, Pi/2}, {-2, 3.}}]}, 
    Alignment -> {Left, 0.8}]]], {{t, 0.01, Style["t", Italic]}, 
  0.01, \[Pi]/2, .01, ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{\[Theta], .78}, 0, \[Pi]/2, .01, 
  ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{m1, .5, 
   Text@Subscript[Style["m", Italic], 1]}, .25, .75, .01, 
  ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{m2, .5, 
   Text@Subscript[Style["m", Italic], 2]}, .25, .75, .01, 
  ImageSize -> Tiny, 
  Appearance -> "Labeled"}, {{\[Mu], .5}, .25, .75, .01, 
  ImageSize -> Tiny, Appearance -> "Labeled"}, 
 ControlPlacement -> Left]

enter image description here

$\endgroup$
2
  • $\begingroup$ What does this line : Plot[a x, {x, 0, t}, plot? How can I modify it to plot velocity over time $\endgroup$
    – usernew
    Commented Feb 25, 2021 at 20:49
  • $\begingroup$ @usernew The purpose was just to show a way to include a dynamic plot with your animation. I did not analyze the code from the point of view of physics. I used t because it is changing but I am not quite sure about what it represents (I see it is assigned an inverse of a in a Which statement) . $\endgroup$ Commented Feb 25, 2021 at 22:36

Your Answer

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

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