Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %matplotlib
- import numpy as np
- from mpl_toolkits.mplot3d import Axes3D
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- theta = np.pi/4
- l0 = 0.2
- x = 3*l0/2
- dt = 0.001
- t = 0
- k = 2
- m = 1
- theta1 = 0
- x1 = 0
- T, X, THETA = ([], [], [])
- X1, THETA1 = ([], [])
- while t<20:
- T.append(t)
- X.append(x)
- X1.append(x1)
- THETA.append(theta)
- THETA1.append(theta1)
- theta2 = 9.8*np.sin(theta)/x
- x2 = 9.8*np.cos(theta)-k*x/m
- theta = theta+theta1*dt
- theta1 = theta1+theta2*dt
- x = x+x1*dt
- x1 = x1+x2*dt
- t=t+dt
- X = np.array(X)
- X1 = np.array(X1)
- THETA = np.array(THETA)
- THETA1 = np.array(THETA1)
- fig, ax = plt.subplots()
- # ax.plot(-(X+l0)*np.sin(THETA), (X+l0)*np.cos(THETA))
- ax.plot(T, X)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement