Changed ode folder to be named diffyq, since many of these are pde videos

This commit is contained in:
Grant Sanderson
2019-06-19 16:10:21 -07:00
parent 2f6be9a389
commit 96e34b969c
26 changed files with 20516 additions and 0 deletions

View File

@ -0,0 +1,63 @@
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