# 有多无聊：弹性碰撞与Python代码

in cn •  2 months ago

(图源 ：pixabay)

# Python代码

``````def collision(m1, v1, m2, v2):
va = (v1*(m1 - m2) + 2*m2*v2)/(m1 + m2)
vb = (v2*(m2 - m1) + 2*m1*v1)/(m2 + m1)
return va, vb
``````

`v1 < 0 and v2<=0 and abs(v1) >= abs(v2)`

`v2 = -1*v2`

``````def func_times(m1, v1, m2, v2):
times = 0
while(True):
if(v1 < 0 and v2<=0 and abs(v1) >= abs(v2)):
break
v1, v2 = collision(m1, v1, m2, v2)
times = times +1

if(v1 < 0 and v2<=0 and abs(v1) >= abs(v2)):
break

v2 = -1*v2
times = times +1

return times
``````

# 见证奇迹

``````m1 = 100
m2 = 100
v1 = 100
v2 = 0
for i in range(0, 7):
m1 = 100*100**i
times = func_times(m1, v1, m2, v2)
print(f"M1:{m1}, M2:{m2}, v1:{v1}, v2:{v2}, Times:{times}")
``````

(图源 ：pixabay)

# 相关链接

Vote For Me As Witness
https://steemit.com/~witnesses type in `oflyhigh` and click `VOTE`

Vote @oflyhigh via Steemconnect
Thank you!

Sort Order:
·  2 months ago

!thumbup

@justyy 是CN区的见证人，请支持他，给他投票，或者设置justyy为见证人代理。感谢！@justyy的主要贡献：https://steemyy.com

Congratulations! This post has been selected by @justyy as today's (2019-10-17) 【Good Posts】, Steem On! Reply to this message in 24 hours to get rewards. Upvote this comment to support the @dailychina and increase your future rewards! ^_^

If you believe what I am doing, please consider a spare vote voting me here, thank you very much indeed.

@justyy - the author of https://SteemYY.com and I have been a Steem Witness for more than a year now.

·  2 months ago

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.22% upvote! Together, let’s change the world!

·  2 months ago

This post has been voted on by the SteemSTEM curation team and voting trail. It is elligible for support from @curie and @minnowbooster.

If you appreciate the work we are doing, then consider supporting our witness @stem.witness. Additional witness support to the curie witness would be appreciated as well.