# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
# Get started with interactive Python!
# Supports Python Modules: builtins, math,pandas, scipy
# matplotlib.pyplot, numpy, operator, processing, pygal, random,
# re, string, time, turtle, urllib.request
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy as sp
# Pendulum Parameters
g = 9.8
L = 1
# We need an array of time points from 0 to 10 in increments of 0.01 seconds
dt = 0.001
t_vec = np.arange(0,10,dt)
# Initialize a vector of zeros
theta_vec = np.zeros(len(t_vec))
dtheta_vec = np.zeros(len(t_vec))
# Set our initial condition
theta_vec[0] = np.pi/4 # initial angle
dtheta_vec[0] = 0 # initial angular velocity
# Loop through time
# Euler's Method (approximately integrates the differential equation)
for i in range(1, len(t_vec)):
theta_vec[i] = theta_vec[i-1] + dtheta_vec[i-1]*dt
dtheta_vec[i] = dtheta_vec[i-1] + (-g/L*np.sin(theta_vec[i-1]))*dt
plt.plot(t_vec,theta_vec)
plt.show()