Week 3 - Solving second order ODEs
Objective-To simulate the transient behaviour of a simple pendulum and to animate the oscillation using MATLAB.
Theory-A simple pendulum consists of a relatively massive object hung by a string from a fixed support. It typically hangs vertically in its equilibrium position. The massive object is affectionately referred to as the pendulum bob. When the bob is displaced from equilibrium and then released, it begins its back and forth vibration about its fixed equilibrium position. The motion is regular and repeating, an example of periodic motion.

On Solving, We get a Ordinary Differential equation of 2nd Order that describes the position of the ball with respect to time. The equation is given below:

In this Equation:
b= Damping Coefficient, i.e. 0.05
m= mass of the bob i.e. 1 kg
L= Length of the string i.e. 1 m
g= Acceleration due to gravity i.e. 9.8 m/s^2
We need to convert the above given 2nd order ODE to two 1st order ODE and simulate the motion.
Code-
- Input of value given b,m,L,g.
- Create an array theta_0 to store the initial displacement as 0m/s and Initial velocity as 3 rad/sec
- Create an array to store time from 0 to 20 with 300 values in between.
- Solving the ODE by using function ode45
- Defining another function as ode_function to solve the ODE by taking inputs of t, theta, b,g,L,m.
- Plot the graph for time vs Displacement and Velocity.
- A for loop is used to locate the position of the bob and for each position is stored in array M
- Create a movie animation
ERROR-
Forgot hold off command

After giving this command it solved.
2.forgot to giving comma character

After giving this it solved.
Output-
Plot velocity-displacement and time curve

Animation link-
https://youtu.be/PJeWxUN_zqA