Week 3 - Solving second order ODEs
Aim : To solve second order diffrential equation using Matlab.
Objectives :
1. Write a program in Matlab\Octave that will simulate the pendulum motion.
Your objective is to write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping
In the above equation,
g = gravity in m/s2,
L = length of the pendulum in m,
m = mass of the ball in kg,
b=damping coefficient.
2. Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.
Write a program in Matlab\Octave that will simulate the pendulum motion, just like the one shown in the start of this challenge.
use,
L=1 metre,
m=1 kg,
b=0.05.
g=9.81 m/s2.
Theory :
A pendulum is a body suspended from a fixed point so that it can swing back and forth under the influence of gravity. The time interval of a pendulum's complete back-and-forth movement is constant. When a pendulum is displaced sideways from its resting, equilibrium position, it is subject to a restoring force due to gravity that will accelerate it back toward the equilibrium position. When released, the restoring force acting on the pendulum's mass causes it to osciliate about the equilibrium position, swinging back and forth. The time for one complete cycle, a left swing and a right swing, is called the period. The period depends on the length of the pendulum and also to a slight degree on the amplitude the width of the pendulum's swing.

The point from which bob is suspended is known as part of suspension. Weight of the bob acts vertically downwards and the tesnsion acts vertically upwards. So the bob comes under equilibrium position and the bob starts osciliating if even smaller external force is applied.
Procedure / Explanation :
Governing Equation of second order ODE

θ is the angle made by movable link with vertical axis
L is the length of movable rod
m is the mass of the bob, b is the damping coeffieicent od the system.
-------------> second order ODE------(1)
To solve this ODE we need to reduce the order of equation in to lower order
let θ = θ1

Now we derived (1) and (2) equation,
Given details,
simulate the motion between 0-20 sec
for angular displacement = 0
at Time = 0
angular velocity = 3 rad/sec
L =1 m
m = 1 kg
b=0.05.
g=9.81 m/s2.
- assign the given parameters as variables in the code. The time span of the pendulum is set by usinglinspace command, theta value is given as a column matrix.
- we have write ode45 function and name the function as ode_func as same as the name in the function
- Plot a graph corrsponding to time and velocity, put a legend to identify the each values of the graph.
- for accurate simulation of the simple pendulum corresponding to second order ode with damping we need to use the looping statements, here for loop is used to create.
- The pendulum has fixed cocordinates mentioned as x0,y0 and x1y1 are the second coordinates
- marker command is used for making motion of the bon for the pendulum, the axis is fixed using axis command
- The countour command is used to make the value changes in each for loop. the videowiter command is used to create the video file.
- Save the video and closw the video by giving save video_file and close video_file commands and uploaded the video in youtube.
Code used :
Programming language : Matlab
1. code function of ode45 for main program -
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('velocity')
xlabel('time')
legend('displacement', 'angular velocity')
grid on
hold off
plot([-0.5 0.5],[0 0],'lineWidth',2,'Color','black')
hold on
plot([0 0],[-1.5 0.5],'LineStyle','--','Color','black')
plot([x0 x1],[y0 y1],'LineWidth',1,'Color','b')
plot(x0, y0,'o','MarkerSize',4,'MarkerFaceColor',[0.6 0.6 0.6]);
plot(x1, y1,'o','MarkerSize',20,'MarkerFaceColor','r')
axis([-1.5 1.5 -1.5 0.5])
pause(0.01)
M(ct) = getframe(gcf);
ct = ct+1;
hold off
Results :
1. graph represents the pendulum motion :

2. Simulated the motion between for given angular displacement and angular velocity
Animation link of the simple pendulum.
Errors occured :
error occured while plotting the bob motion, markersize, linestyle, markerface color inputs not given propely. It is corrected by checking inputs properly after several trails by executing the program.

References :