Reputation: 11
i've spent some time trying to figure out how to simulate the motion of a pendulum, and i've got something that looks like its a pendulum, but i know that doesn't mean it is a pendulum! i realise the code isn't as clean as it could be but i'm fairly new to this so my main issue is making sure it works!
from matplotlib import pyplot as plt
import math
import statistics
import numpy as np
A = 80
l = 100
g = 9.81
plt.ion()
for t in np.arange(1, 300, 0.4):
w = math.sqrt(g/l)
x = A*math.sin(w*t)
v = w*A*math.cos(w*t)
#h = -(1/2*(v**2))/9.81
h1 = math.sqrt(l**2 - x**2)
if v == 0:
x = A
h = l - h1
px = 0
py = 50
x1 = np.arange(-20, 20, 0.5)
m = (h-py) / (x-px)
C = 50
y = m*x1+C
plt.clf()
plt.errorbar(x, h, fmt = 'o', markersize = 20)
#plt.plot(x1,y)
plt.xlim(-100, 100)
plt.ylim(-15, 100)
plt.show()
plt.pause(0.01)
Upvotes: 1
Views: 65