在無風情況下的噴泉模擬
我的python代碼
import numpy as np import random import matplotlib matplotlib.rcParams['font.sans-serif']=[u'simHei'] matplotlib.rcParams['axes.unicode_minus']=False import matplotlib.pyplot as plt tt = np.linspace(0,4,1000) #y = -tt**2+4*tt #plt.plot(tt,y,linestyle='--') # 沒有風 vy0=10 g=10 vx0=5 x=[] y=[] x0=0 y0=0 dt = 4/1000 x.append(x0) y.append(y0) for t in tt: y0 += vy0*dt x0 += vx0*dt vy0 -= g*dt x.append(x0) y.append(y0) if y0<0: break plt.plot(x,y,linestyle='--')
在右邊風情況下的噴泉模擬
我的python代碼
# 有向右的風 vy0=10 g=10 vx0=5 a = 1.5 x=[] y=[] x0=0 y0=0 dt = 4/1000 x.append(x0) y.append(y0) for t in tt: y0 += vy0*dt x0 += vx0*dt vy0 -= g*dt vx0 -= a*dt x.append(x0) y.append(y0) if y0<0: break plt.plot(x,y)
在左邊風情況下的噴泉模擬
我的python代碼
# 有向左的風 vy0=10 g=10 vx0=5 a = -1.5 x=[] y=[] x0=0 y0=0 dt = 4/1000 x.append(x0) y.append(y0) for t in tt: y0 += vy0*dt x0 += vx0*dt vy0 -= g*dt vx0 -= a*dt x.append(x0) y.append(y0) if y0<0: break plt.plot(x,y)
所有代碼

# -*- coding: utf-8 -*- import numpy as np import random import matplotlib matplotlib.rcParams['font.sans-serif']=[u'simHei'] matplotlib.rcParams['axes.unicode_minus']=False import matplotlib.pyplot as plt tt = np.linspace(0,4,1000) #y = -tt**2+4*tt #plt.plot(tt,y,linestyle='--') # 沒有風 vy0=10 g=10 vx0=5 x=[] y=[] x0=0 y0=0 dt = 4/1000 x.append(x0) y.append(y0) for t in tt: y0 += vy0*dt x0 += vx0*dt vy0 -= g*dt x.append(x0) y.append(y0) if y0<0: break plt.plot(x,y,linestyle='--') # 有向右的風 vy0=10 g=10 vx0=5 a = 1.5 x=[] y=[] x0=0 y0=0 dt = 4/1000 x.append(x0) y.append(y0) for t in tt: y0 += vy0*dt x0 += vx0*dt vy0 -= g*dt vx0 -= a*dt x.append(x0) y.append(y0) if y0<0: break plt.plot(x,y) # 有向左的風 vy0=10 g=10 vx0=5 a = -1.5 x=[] y=[] x0=0 y0=0 dt = 4/1000 x.append(x0) y.append(y0) for t in tt: y0 += vy0*dt x0 += vx0*dt vy0 -= g*dt vx0 -= a*dt x.append(x0) y.append(y0) if y0<0: break plt.plot(x,y)
噴泉散落在地上模擬
import numpy as np import random import matplotlib matplotlib.rcParams['font.sans-serif']=[u'simHei'] matplotlib.rcParams['axes.unicode_minus']=False import matplotlib.pyplot as plt from scipy.stats import norm a1_list = random.uniform(0,0.5) # 生成一組正太分布的加速度,均值是0,方差是0.5 a1_list = norm.rvs(a1_list, size=1000) a2_list = random.uniform(0,0.5) a2_list = norm.rvs(a2_list, size=1000) X0=[] X1=[] # 對每一組加速度 for i in range(1000): vy0=10 g=10 vx0=5 vx1=5 a1 = a1_list[i] a2 = a2_list[i] x0=0 x1=0 y0=0 dt = 4/1000 for t in tt: y0 += vy0*dt x0 += vx0*dt x1 += vx1*dt vy0 -= g*dt vx0 -= a1*dt vx1 -= a2*dt if y0<0: break X0.append(x0) X1.append(x1) plt.scatter(X0,X1)
炫酷噴泉三維圖
from mpl_toolkits.mplot3d import axes3d from scipy.stats import norm a1_list = random.uniform(0,0.2) # 生成一組正太分布的加速度,均值是0,方差是0.5 a1_list = norm.rvs(a1_list, size=100) a2_list = random.uniform(0,0.2) a2_list = norm.rvs(a2_list, size=100) X0=[] X1=[] # 對每一組 ax=plt.subplot(111,projection='3d') for i in range(100): vy0=10 g=10 vx0=5 vx1=5 a1 = a1_list[i] a2 = a2_list[i] xx0=[] xx1=[] y=[] x0=0 x1=0 y0=0 dt = 4/1000 for t in tt: y0 += vy0*dt x0 += vx0*dt x1 += vx1*dt vy0 -= g*dt vx0 -= a1*dt vx1 -= a2*dt xx0.append(x0) xx1.append(x1) y.append(y0) if y0<0: break # X0.append(x0) # X1.append(x1) ax.plot(xx0,xx1,y,'--') plt.show()