TransWikia.com

perpectly elastic collision pi model

Mathematica Asked by user21427 on September 24, 2020

Can you make a model like the video below? It’s so amazing that I want to check it out.
enter link description here

One Answer

It is really amazing that Pi pops up. Here is a simulation, using constant energy and elastic collision with momentum conservation. Note that by a collision with the wall, energy stays constant, but momentum changes.

m1 = 1; m2 = 10;(*masses*)
x10 = 1; x20 = 2; (*initial locations*)
v10 = 0; v20 = -1;(*inital velocities*)
etot = m1 v10^2 + m2 v20^2;(*const energy*)
tmax =10; (*max. time for solution*)
newvelocity[vv1_, 
  vv2_] := (tsol = 
   Quiet[Solve[{m1 vn1 + m2 vn2 == m1 vv1 + m2  vv2, 
      m1 vn1^2 + m2 vn2^2 == etot}, {vn1, vn2}]]; {vn1, vn2} /. 
   If[Sign[tsol[[1, 1, 2]]] != Sign[vv1], tsol[[1]], tsol[[2]]]);

sol = NDSolve[{x1'[t] == v1[t], x2'[t] == v2[t], x1[0] == x10, 
    x2[0] == x20, v1[0] == v10, v2[0] == v20, 
    WhenEvent[
     x1[t] == x2[t], {tsol = newvelocity[v1[t], v2[t]], 
      v1[t] -> tsol[[1]], v2[t] -> tsol[[2]] }], 
    WhenEvent[x1[t] == 0, v1[t] -> -v1[t]]}, {x1, x2, v1, v2}, {t, 0, 
    tmax}, DiscreteVariables -> {v1, v2}];
Plot[{ x1[t], x2[t]} /. sol // Evaluate, {t, 0, tmax}, 
 PlotLegends -> {"m1", "m2"}, AxesLabel -> {"time", "space"}, PlotLabel -> 
 "Expected # of collisions:"<>ToString[Floor[Pi/ArcTan[Sqrt[m1/m2]]]]]

enter image description here

Correct answer by Daniel Huber on September 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP