Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
74 views
ubuntu2004
Kernel: Python 3 (system-wide)
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation N = 1 L = 1 dt = 0.01 def update_pos(num, pos, vel, pt): for i in range(N): t1 = pos[i] pos[i] = pos[i] + vel[i]*dt if pos[i][0] < 0 or pos[i][0] > L: pos[i][0] = t1[0] vel[i][0] = -vel[i][0] if pos[i][1] < 0 or pos[i][1] > L: pos[i][1] = t1[1] vel[i][1] = -vel[i][1] pt.set_data(pos[:,0], pos[:,1]) return pt pos = L*np.random.rand(N, 2) vel = np.random.rand(N, 2) fig1 = plt.figure() pts, = plt.plot([], [], 'bo', markersize=20) plt.xlim(0,L) plt.ylim(0,L) ball_ani = animation.FuncAnimation(fig1, update_pos, frames=25, fargs=(pos, vel, pts), interval=50) from IPython.display import HTML HTML(ball_ani.to_jshtml())
WARNING: Some output was deleted.
N = 2 L = 1 dt = 0.01 def update_pos(num, pos, vel, pt): for i in range(N): t1 = pos[i] pos[i] = pos[i] + vel[i]*dt if pos[i][0] < 0 or pos[i][0] > L: pos[i][0] = t1[0] vel[i][0] = -vel[i][0] if pos[i][1] < 0 or pos[i][1] > L: pos[i][1] = t1[1] vel[i][1] = -vel[i][1] pt.set_data(pos[:,0], pos[:,1]) return pt pos = L*np.random.rand(N, 2) vel = np.random.rand(N, 2) fig1 = plt.figure() pts, = plt.plot([], [], 'bo', markersize=20) plt.xlim(0,L) plt.ylim(0,L) ball_ani = animation.FuncAnimation(fig1, update_pos, frames=25, fargs=(pos, vel, pts), interval=50) from IPython.display import HTML HTML(ball_ani.to_jshtml())
WARNING: Some output was deleted.
N = 10 L = 1 dt = 0.01 def update_pos(num, pos, vel, pt): for i in range(N): t1 = pos[i] pos[i] = pos[i] + vel[i]*dt if pos[i][0] < 0 or pos[i][0] > L: pos[i][0] = t1[0] vel[i][0] = -vel[i][0] if pos[i][1] < 0 or pos[i][1] > L: pos[i][1] = t1[1] vel[i][1] = -vel[i][1] pt.set_data(pos[:,0], pos[:,1]) return pt pos = L*np.random.rand(N, 2) vel = np.random.rand(N, 2) fig1 = plt.figure() pts, = plt.plot([], [], 'bo', markersize=20) plt.xlim(0,L) plt.ylim(0,L) ball_ani = animation.FuncAnimation(fig1, update_pos, frames=25, fargs=(pos, vel, pts), interval=50) from IPython.display import HTML HTML(ball_ani.to_jshtml())
WARNING: Some output was deleted.
N = 100 L = 1 dt = 0.1 def update_pos(num, pos, vel, pt): for i in range(N): t1 = pos[i] pos[i] = pos[i] + vel[i]*dt if pos[i][0] < 0 or pos[i][0] > L: pos[i][0] = t1[0] vel[i][0] = -vel[i][0] if pos[i][1] < 0 or pos[i][1] > L: pos[i][1] = t1[1] vel[i][1] = -vel[i][1] pt.set_data(pos[:,0], pos[:,1]) return pt pos = L*np.random.rand(N, 2) vel = np.random.rand(N, 2) fig1 = plt.figure() pts, = plt.plot([], [], 'bo', markersize=20) plt.xlim(0,L) plt.ylim(0,L) ball_ani = animation.FuncAnimation(fig1, update_pos, frames=25, fargs=(pos, vel, pts), interval=50) from IPython.display import HTML HTML(ball_ani.to_jshtml())
WARNING: Some output was deleted.
por alguna razon que no logre descubrir las particulas no se mueven, si es posible me puede indicar que esta mal en codigo, para poder saber el porque no precentan movimiento.