Week 3 - Solving second order ODEs
Objective:
the project aims to stimulate the movement of the simple pendulum (0-20s) which moves according to the below second order differential equation (ODE) and to create an animation of its movement using python.
Procedure:
The equation of simple pendulum using damping is a second-order differential equation (ODE). So, it must be divided into two lower-order differential equation
d`theta`1/d`theta`2=`theta2`
d`theta2`/dt=-(b/m).`theta2`-(g/l).sin`theta1`
However, some assumption are made for converting the second order ode to first order ode.
thet are
`theta`=`theta1`
d`theta/dt`=`d theta1 /dt`=`theta2`
`d^2 theta/dt=d/dt(d theta1/dt)=d theta2/dt`
As the material is fixed the damping coefficient 'b' is also fixed (because it is a material property ).length of the strings and mass of the bob are also specified.
Code:
- Import numpy,matplotlib, math modules for array, plottting and math operation respectively.
- The 'odeint' module extracted from 'scipy.integrate' module to solve the given ode.
- Divide higher-order ODE into the first -order and define in the function.
- Define the initial condition and angular velocity and displacement. The simulation time is taken in the range of 0-20 seconds.
- To solve the ODE call the odeint module and given the define module and given the define variable Then plot araph between the time vs displacement and time vs angular velocity.
- Create a loop to obtain animation of the motion of the simple pendulum bob and convert the obtained images into gif file by using the 'imgflip'.