Python動力系統(tǒng)驗證三體人是否真的存在
隨機三體
目前來說我們并不關心真實的物理對象,而只想看一下三個隨機的點放在三個隨機的位置,賦予三個隨機的速度,那么這三個點會怎么走。所以其初始化過程為
m = np.random.rand(3) x = np.random.rand(3) y = np.random.rand(3) u = np.random.rand(3) v = np.random.rand(3)
得到三個隨機的運動為



這幾個隨機的三體均有一個共同的結局,二體尚存,三體皆四散而去,至于能不能重新相聚,那就很難說了,代碼為
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
m = np.random.rand(3)
x = np.random.rand(3)
y = np.random.rand(3)
u = np.random.rand(3)
v = np.random.rand(3)
fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(xlim=(-2e11,2e11),ylim=(-2e11,2e11))
ax.grid()
trace0, = ax.plot([],[],'-', lw=0.5)
trace1, = ax.plot([],[],'-', lw=0.5)
trace2, = ax.plot([],[],'-', lw=0.5)
pt0, = ax.plot([x[0]],[y[0]] ,marker='o')
pt1, = ax.plot([x[0]],[y[0]] ,marker='o')
pt2, = ax.plot([x[0]],[y[0]] ,marker='o')
k_text = ax.text(0.05,0.85,'',transform=ax.transAxes)
textTemplate = 't = %.3f days\n'
N = 1000
dt = 36000
ts = np.arange(0,N*dt,dt)/3600/24
xs,ys = [],[]
for _ in ts:
x_ij = (x-x.reshape(3,1))
y_ij = (y-y.reshape(3,1))
r_ij = np.sqrt(x_ij**2+y_ij**2)
for i in range(3):
for j in range(3):
if i!=j :
u[i] += (m[j]*x_ij[i,j]*dt/r_ij[i,j]**3)
v[i] += (m[j]*y_ij[i,j]*dt/r_ij[i,j]**3)
x += u*dt
y += v*dt
xs.append(x.tolist())
ys.append(y.tolist())
xs = np.array(xs)
ys = np.array(ys)
def animate(n):
trace0.set_data(xs[:n,0],ys[:n,0])
trace1.set_data(xs[:n,1],ys[:n,1])
trace2.set_data(xs[:n,2],ys[:n,2])
pt0.set_data([xs[n,0]],[ys[n,0]])
pt1.set_data([xs[n,1]],[ys[n,1]])
pt2.set_data([xs[n,2]],[ys[n,2]])
k_text.set_text(textTemplate % ts[n])
return trace0, trace1, trace2, pt0, pt1, pt2, k_text
ani = animation.FuncAnimation(fig, animate,
range(N), interval=10, blit=True)
plt.show()
ani.save("3.gif")
經過多次畫圖,基本上沒發(fā)現能夠穩(wěn)定運行的三體,所以從經驗來說,隨機三體在自然界中應該是很難存在的——畢竟很快就解散了。
三星問題
短時間內穩(wěn)定的三體還是有很多的,比如比如在高中出鏡率極高的三星問題:
即等距等質量三星如何運動?現假設三個質量相同的等距質點,分別給一個隨機的速度,看看它們怎么運動。
m = np.ones(3) r = np.ones(3) theta = np.arange(3)*np.pi*2/3 x = r*np.cos(theta) y = r*np.sin(theta) V = np.random.rand(N) u = V*np.sin(theta) v = V*np.cos(theta)


總之只要看到它們互相靠近,那么結果注定分道揚鑣,像極了人生。
如果再讓它們速度相等,那么神奇的一幕出現了


但更神奇的是,只要對速度做出一點點的更改,例如令第三顆星在橫軸方向更改 δ ,則會出現如下場景

δ=0.0001

這就是所謂的蝴蝶效應,初值的一點更改,就會造成不可挽回的巨大后果,這也是動力系統(tǒng)的獨特魅力。
以上就是Python動力系統(tǒng)驗證三體人是否真的存在的詳細內容,更多關于Python驗證三體人是否存在的資料請關注腳本之家其它相關文章!
相關文章
Python 的第三方調試庫 ???pysnooper?? 使用示例
這篇文章主要介紹了Python 的第三方調試庫 ???pysnooper?? 使用示例的相關資料,需要的朋友可以參考下2023-02-02
在pytorch中動態(tài)調整優(yōu)化器的學習率方式
這篇文章主要介紹了在pytorch中動態(tài)調整優(yōu)化器的學習率方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06

