Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.animation as anim
- n = 2
- lenght = 100
- dt = 0.01
- epsilon = 2250 # energía mínima
- sigma = 26 # distancia a la cuál es 0
- def u(r):
- return 4*epsilon*(pow(sigma/r, 12) - pow(sigma/r, 6))
- def f(r):
- return 4*epsilon*(12*sigma**12/r**13 - 6*sigma**6/r**7)
- def update(num, pos, pos1, pt):
- aceleraciones = np.zeros((n, 2))
- for i in range(n):
- acc = 0.0
- for j in range(n):
- if i != j:
- d = np.linalg.norm(pos1[i] - pos1[j])
- acc += f(d) * (pos1[i] - pos1[j])/d
- pass
- pass
- aceleraciones[i] = acc
- pass
- pos1c = np.copy(pos1)
- for i in range(n):
- pos1[i] = 2*pos1[i] - pos[i] + aceleraciones[i]*dt**2
- for j in range(2):
- if pos1[i][j] < 0 or pos1[i][j] > lenght: # si colide con los bordes
- pos1[i][j] = pos1c[i][j] # no avanza
- pass
- for i in range(n):
- pos[i] = pos1c[i]
- pass
- pt.set_data(pos1[:, 0], pos[:, 1])
- return pt
- fig1 = plt.figure()
- pos = np.array([[30, 50], [70, 50]], dtype="float64")
- vel = np.array([[0, 40], [0, -40]], dtype="float64")
- # primer paso
- acc = 0.0
- for i in range(n):
- for j in range(n):
- if i != j:
- d = np.linalg.norm(pos[i] - pos[j])
- acc += f(d) * (pos[i] - pos[j])/d
- pos1 = pos + vel*dt + acc*dt**2/2
- pts, = plt.plot([], [], "bo", markersize=10)
- plt.xlim(0, lenght)
- plt.ylim(0, lenght)
- booru = anim.FuncAnimation(fig1, update, fargs=(pos, pos1, pts), interval=50)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement