1
$\begingroup$

I am told to animate two beads sliding on rails in Mathematica, but I am very confused on how to get a mass on a rail and it move up and down the rail.

Two sticks with two masses. Mass on stick x moves up and down the stick.

$\endgroup$

closed as off-topic by Daniel Lichtblau, m_goldberg, MarcoB, bbgodfrey, Carl Lange Apr 24 at 21:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Daniel Lichtblau, m_goldberg, MarcoB, bbgodfrey, Carl Lange
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Have you been able to model a single sliding bead yet? Any code to share? $\endgroup$ – MikeY Apr 20 at 11:43
  • $\begingroup$ Is it 2D or 3D? $\endgroup$ – Alex Trounev Apr 20 at 19:19
6
$\begingroup$

If there are no restrictions on r, x, then the solution is

eq = {x''[t] == -k*(x[t] - r[t]*Cos[theta]), 
   r''[t] == -k*(r[t] - x[t]*Cos[theta])};

theta = Pi/4; k = 1;
ic = {x[0] == 1, r[0] == 0, x'[0] == 0, r'[0] == 0};
sol = NDSolve[{eq, ic}, {x, r}, {t, 0, 20}]

lst = Table[
   Graphics[{{Line[{{-1, 0}, {1, 0}}], 
      Line[{{-Cos[theta], -Sin[theta]}, {Cos[theta], 
         Sin[theta]}}]}, {Green, 
      Line[{{x[t], 0}, {r[t]*Cos[theta], r[t]*Sin[theta]}} /. 
        sol]}, {Red, PointSize[.05],  Point[{x[t], 0} /. sol], 
      Point[{r[t]*Cos[theta], r[t]*Sin[theta]} /. sol]}}], {t, 0, 
    10, .1}];

 ListAnimate[lst]

fig1

$\endgroup$

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