0

I am using another person's code to try and demonstrate this problem in physics:

a large mass M collides with a smaller mass m, which then moves moves to rebound off a wall returning to collide with the larger mass M. This process repeats until larger mass has turned and its velocity sign flips. If the mass of the larger block is 16*100^n (where n is an integer) times more massive than the first block the number of collisions between the large block and the small block compute the (n+1) digits of pi. For example: when the block is 1600 times bigger there are 31 collisions. If the block is 16000000 there are be 3141 collisions.

I did my code in vPython and it works, but only until a certain amount. I was able to get 31415 collisions when the original code. When I make N=5 the simulation completely fails and the screen turns black. Apparently this is because the time step is not small enough. So I tried to make it smaller and see if it can compute more numbers and it does. I was able to count 314159 collisions by changing the time step to 0.00001. But then I input N=6 and again it collapses. So I try to increase the time step to 0.000001 and it works but only gives me the number 3.14159e+6 without the extra digit of pi.

enter image description here

Can someone please tell why this is. Why do I not get the next digit. Is my computer not strong enough. I do not need to actually fix this problem, that is not the point, I just need to understand the limitations of my simulation and computer and why it cannot compute the next digit.

YakovL
  • 7,557
  • 12
  • 62
  • 102
  • 4
    Please don’t post code as image. You wrote it as text, so put it here as text. Otherwise nobody can even try it. – Sami Kuhmonen Feb 17 '19 at 10:15
  • may be it's worth mentioning that 314159 is close to pi*10^5 – YakovL Feb 17 '19 at 19:48
  • Without seeing the whole program, I may be wrong, but this sounds like at some step in the process you have a number that is either very large (something like 1e300) or very small (something like 1e-300), and the algorithm exceeds the capability of 64-bit floating-point numbers. – user1114907 Apr 22 '19 at 02:16

0 Answers0