# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import ipywidgets as widgets
from math import *
from scipy import *
import numpy as np
import matplotlib.pyplot as plt

widgets.FloatSlider(
    min=-10,
    max=10,
    step=0.1,
    description='Slider:',
    value=5
)

# +
slid_data_points = widgets.IntSlider(
    min=100,
    max=10100,
    step=1000,
    description='Data Points:',
    value=4100
)

slid_angle = widgets.IntSlider(
    min=-720,
    max=720,
    step=1,
    description='Angle:',
    value=180
)

slid_angle_vel = widgets.IntSlider(
    min=-720,
    max=720,
    step=1,
    description='Angle Vel.:',
    value=5
)

slid_damping_force = widgets.FloatSlider(
    min=0,
    max=2,
    step=0.01,
    description='Damp:',
    value=0.05
)

slid_driving_force = widgets.FloatSlider(
    min=-1,
    max=1,
    step=0.01,
    description='Drive:',
    value=0.05
)

slid_frequency = widgets.FloatSlider(
    min=-1,
    max=1,
    step=0.01,
    description='Freq:',
    value=1/3
)
slid_dt = widgets.FloatSlider(
    min=0,
    max=1,
    step=0.01,
    description='Time Step:',
    value=0.05
)


def create_graph(points,angle,ang_vel,damp,drive,freq,time_step):
    #From Simulation and Visualization of Chaos in a Driven Nonlinear Pendulum 
    #– An Aid to Introducing Chaotic Systems in Physics by <NAME> and <NAME>
    #With modifications to constants and updates to compile without error

    #Initial theta values
    theta0 = angle *2*pi/360
    omega0 = ang_vel*2*pi/360

    #Constants
    length_of_string = 9.8
    gravity = 9.8
    drive_frequency = freq
    damping_force = damp

    #Defining the driving force - controls the chaos
    FD = drive

    #Assigning the number of data points to be considered
    data_points = points

    #Preallocating space for time, theta and omega
    time = np.zeros(data_points)
    theta = np.zeros(data_points)
    omega = np.zeros(data_points)

    #Initializing theta and omega
    theta[0] = theta0
    omega[0] = omega0

    #Defining time step size
    dt = time_step

    for i in range(0,data_points - 1):
         time[i+1] = time[i] + dt

         #Calculating for FD = 0, 0.1... in omegas
         omega[i+1] = omega[i] - (gravity/length_of_string)*np.sin(theta[i])*dt - (damping_force*omega[i]*dt +FD*np.sin(drive_frequency*time[i])*dt)
         theta[i+1] = theta[i] + omega[i+1]*dt

    plt.plot(time,theta)
    plt.ylabel("theta")
    plt.xlabel("time")
    plt.show()

    plt.plot(time,omega)
    plt.ylabel("omega")
    plt.xlabel("time")
    plt.show()
widgets.interact(create_graph, points = slid_data_points,angle = slid_angle,ang_vel = slid_angle_vel,damp=slid_damping_force,drive=slid_driving_force,freq=slid_frequency,time_step=slid_dt)


StarcoderdataJupyterScriptsDedupFiltered