mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 20:43:56 +08:00
64 lines
812 B
Python
64 lines
812 B
Python
import numpy as np
|
|
|
|
# Physical constants
|
|
g = 9.8
|
|
L = 2
|
|
mu = 0.1
|
|
|
|
THETA_0 = np.pi / 3 # 60 degrees
|
|
THETA_DOT_0 = 0 # No initial angular velocity
|
|
|
|
# Definition of ODE
|
|
def get_theta_double_dot(theta, theta_dot):
|
|
return -mu * theta_dot - (g / L) * np.sin(theta)
|
|
|
|
|
|
# Solution to the differential equation
|
|
def theta(t):
|
|
# Initialize changing values
|
|
theta = THETA_0
|
|
theta_dot = THETA_DOT_0
|
|
delta_t = 0.01 # Some time step
|
|
for time in np.arange(0, t, delta_t):
|
|
# Take many little time steps of size delta_t
|
|
# until the total time is the function's input
|
|
theta_double_dot = get_theta_double_dot(
|
|
theta, theta_dot
|
|
)
|
|
theta += theta_dot * delta_t
|
|
theta_dot += theta_double_dot * delta_t
|
|
return theta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|