在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在无风情况下的喷泉模拟 我的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()
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论