All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
OBJECTIVE: To solve the equation of motion of simple pendulum which is a second order ODE and to simulate the motion of the simple pendulum with damping INTRODUCTION: Differential equations appear in a wide range of problems in physics and science. They are use to model many of the phenomenon that occur around us and we…
Nitesh Kumar Gautam
updated on 24 Mar 2021
OBJECTIVE:
To solve the equation of motion of simple pendulum which is a second order ODE and to simulate the motion of the simple pendulum with damping
INTRODUCTION:
Differential equations appear in a wide range of problems in physics and science. They are use to model many of the phenomenon that occur around us and we need to solve differential equations to analyse those phenomena. Some simple examples of modelling using differential equations include:
Simple Pendulum:
A simple pendulum consists of a large mass (bob) suspended by a massless rod or a light string from a rigid support as shown in below figure. The length of the string is large compared to the dimensions of the bob. A stationary pendulum has its string in a vertical position with the bob hanging straight down. This is known as the pendulum's equilibrium position. Oscillations (to and fro motion) are set up in a pendulum by displacing the bob from its equilibrium positions and releasing it.
The point of pivot is taken as (X0,Y0)(X0,Y0) and Bob coordinates are taken as (X1,Y1)(X1,Y1)
INPUT DATA:
1. Length of Pendulum = LL = 1 m
2. Mass of the Bob = mm = 1 kg
3. Acceleration due to gravity = gg = 9.81 ms2ms2
4. Position of Pivot is at Origin.
X0X0 = 0
Y0Y0 = 0
5. Different values of damping coefficient are taken in the problem to identify the effect of damping on simple pendulum
Damping Coefficient = bb = 0.05, 0.1, 0.2, 0.3, 0.4, 0.5
6. Time span is taken as 20 seconds
7. Initial Angular Displacement = 0 radians
8. Initial Velocity of Pendulum = 3 m/s
CALCULATION FORMULAE:
i. Position of pendulum bob at a particular angle θθ is given as
X1=LsinθX1=Lsinθ
Y1=-LcosθY1=−Lcosθ
ii. Equation of motion of simple pendulum with damping is given by
d2θdt2+bmdθdt+gLsinθ=0d2θdt2+bmdθdt+gLsinθ=0 ------(1)
iii. Conversion of Second order ODE in to system of First order ODEs
Let's consider
θ=θ1θ=θ1 ------(2)
dθdt=dθ1dt=θ2dθdt=dθ1dt=θ2 ------(3)
which gives
d2θdt2=ddt(dθdt)=ddt(θ2)=dθ2dtd2θdt2=ddt(dθdt)=ddt(θ2)=dθ2dt ------(4)
Substituting above conditions in equation of simple pendulum with damping
d2θ1dt2+bmdθ1dt+glsinθ1=0d2θ1dt2+bmdθ1dt+glsinθ1=0
dθ2dt+bmθ2+glsinθ1=0dθ2dt+bmθ2+glsinθ1=0
dθ2dt=-bmθ2-glsinθ1dθ2dt=−bmθ2−glsinθ1 ------(5)
by combining ewuations (3) and (5) in to matrix form
ddt[θ1θ2]=[θ2-bmθ2-glsinθ1] ------(6)
CODE ALGORITHM or EXPLANATION:
1. Initial input parameters are assigned. Time span is divided in to particular number of divisions using linspace command.
2. Set of linear first order ODEs (Eq. 6) are solved using 'ode45' sover.
3. Results are plotted between Time and Angular Displacement and Time and Velocity using plot command.
4. In order to simulate the motion of simple pendulum, a 'for' loop is started to determine end positions of pendulum rod (X1,Y1) at each angle of inclination of pendulum.
X1=Lsinθ
Y1=-Lcosθ
5. In order to get animated movie, first plot command is used to plot the position of pendulum rod, second plot command is used to plot pendulum bob at (X1,Y1)and last plot is used to plot the surface to which pendulum bob is suspended. This plot frame is stored in to array M using getframe command
% Plotting of Pendulum link
plot([x0 x1], [y0 y1], 'linewidth', 4, 'color', 'b');
% Plotting of Pendulum Bob
plot(x1, y1, 'o', 'MarkerSize', 10, 'MarkerfaceColor', 'r', 'MarkerEdgeColor', 'r', 'linewidth', 4);
% Plotting surface where Pendulum Bob is suspended
plot([-0.2 0.2], [0 0], 'linewidth', 5, 'color', 'k');
M(count) = getframe(gcf);
gcf returns the current frame handle and count varible is increased by one value
5. 'for' loop is ended and syntax for creating a movie file using VideoWriter command is used.
'ode45' solver syntax:
'ode45' is the most common ODE solver in MATLAB. It is a six-stage, fifth-order, Runge-Kutta method
[t,y] = ode45(odefun,tspan,y0),
where tspan = [t0 tf], integrates the system of differential equations y′=f(t,y) from t0 to tf with initial conditions y0.
Each row in the solution array y corresponds to a value returned in column vector t.
Here we are solving two First Order ODEs simultaneously. Hence 'results' is an array of [Angular Displacement, Velocity]
[t, results] = ode45(@(t, theta) ode_func(t,theta,b,g,l,m), t_span, theta_0);
where
ode_func(t,theta,b,g,l,m) - system of first order ODE in Eq. 6
t_span - time span
theta_0 - Initial conditions of angular displacement and velocity
Upon solving ode_func for each value of time t, angular displacement and velocity are stored in 'results' array
Syntax for creating a movie using VideoWriter from an array M:
Command for VideoWriter
v = VideoWriter(filename,profile) or VideoWriter(filename)
open(v) % Open the video file 'v'
writeVideo(v,M) % Writes data from an array M to the video file 'v'
close(v) % Close the video file 'v'
Different profiles for VideoWriter
'Archival' - Motion JPEG 2000 file with lossless compression
'Motion JPEG AVI' - AVI file using Motion JPEG encoding
'Motion JPEG 2000' - Motion JPEG 2000 file
'MPEG-4' - MPEG-4 file with H.264 encoding
'Uncompressed AVI' - Uncompressed AVI file with RGB24 video
'Indexed AVI' - Uncompressed AVI file with indexed video
'Grayscale AVI' - Uncompressed AVI file with grayscale video
CODE:
% Second Order ODE (Simple Pendulum) Equation
clear all
close all
clc
% Input Parameters
b = 0.05; % Damping Coefficient
l = 1; % Length of the Pendulum in Meters
g = 9.81; % Acceleration due to gravity in m/s^2
m = 1; % Mass of the Pendulum in Kg
% Initial Conditions
theta_0 = [0; 3]; % [Angular Displacement, Velocity] & Angular displacement is taken in radians
% Time limit is divided in to particular number of divisions
t_span = linspace(0,20,500);
% Most commom ODE solver in MATLAB is 'ode45' solver
% 'ode45' is a six-stage, fifth-order, Runge-Kutta method
% [t,y] = ode45(odefun,tspan,y0), where tspan = [t0 tf], integrates the system of differential
% equations y'=f(t,y) from t0 to tf with initial conditions y0.
% Each row in the solution array y corresponds to a value returned in column vector t.
% Here we are solving two First Order ODEs simultaneously
% Hence 'results' is an array of [Angular Displacement, Velocity]
[t, results] = ode45(@(t, theta) ode_func(t,theta,b,g,l,m), t_span, theta_0);
% Plotting
figure(1);
% Time vs Angular Displacement
plot(t,results(:,1), 'linewidth', 2, 'color', 'r')
hold on
% Time vs Velocity
plot(t,results(:,2), 'linewidth', 2, 'color', 'b')
axis([-0.5 20.5 -3.5 3.5])
xlabel('Time')
legend ('Angular Displacement', 'Velocity')
title('When damping coefficient = 0.05')
% Storing angular displacement values from Array 'results' in to seperate Array
theta = results(:,1);
% THETA = theta*(180/pi);
count = 1;
% Loop for creation of Animation
for i = 1:length(theta)
% Position where Pendulum os suspended
x0 = 0;
y0 = 0;
% Position of Pendulum Bob at angle theta(i)
% theta(i) is in radians. Hence sin() and cos() are used instead of sind() and cosd()
x1 = l*sin(theta(i));
y1 = -l*cos(theta(i));
% Plotting
figure(2)
% Plotting of Pendulum link
plot([x0 x1], [y0 y1], 'linewidth', 4, 'color', 'b');
hold on
% Plotting of Pendulum Bob
plot(x1, y1, 'o', 'MarkerSize', 10, 'MarkerfaceColor', 'r', 'MarkerEdgeColor', 'r', 'linewidth', 4);
hold on
% Plotting surface where Pendulum Bob is suspended
plot([-0.2 0.2], [0 0], 'linewidth', 5, 'color', 'k');
axis([-1.5 1.5 -1.5 0.2])
title('Animation of Simple Pendulum (b = 0.05)');
hold off
% Storing the current frame into array M using getframe command
% gcf returns current figure handle
M(count) = getframe(gcf);
count = count + 1;
end
% plays the movie frames in array M once & to play 'n' times use movie(M,n)
movie(M);
%%%%%%%%%%%%%%%%%%%%%%%%%% CREATING VIDEO FILE %%%%%%%%%%%%%%%%%%%%%%%%%
% Using VideoWriter object to create a video file from an array M
% Command for VideoWriter
% v = VideoWriter(filename,profile) or VideoWriter(filename)
%
% Different profiles for VideoWriter
% 'Archival' - Motion JPEG 2000 file with lossless compression
% 'Motion JPEG AVI' - AVI file using Motion JPEG encoding
% 'Motion JPEG 2000' - Motion JPEG 2000 file
% 'MPEG-4' - MPEG-4 file with H.264 encoding
% 'Uncompressed AVI' - Uncompressed AVI file with RGB24 video
% 'Indexed AVI' - Uncompressed AVI file with indexed video
% 'Grayscale AVI' - Uncompressed AVI file with grayscale video
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
v = VideoWriter('simple_pendulum.avi','Uncompressed AVI');
open(v) % Open the video file 'v'
writeVideo(v,M) % Writes data from an array M to the video file 'v'
close(v) % Close the video file 'v'
% ODE FUNCTION FOR SIMPLE PENDULUM
function [dtheta_dt] = ode_func(t,theta,b,g,l,m)
theta1 = theta(1);
theta2 = theta(2);
dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2 - (g/l)*sin(theta1);
dtheta_dt = [dtheta1_dt; dtheta2_dt];
end
OUTPUT:
Time vs Angular Displacement and Velocity plots for various damping coefficients are shown below
It can be observed from above graphs that as the value of damping increases, the values of angular displacement and velocity values decreases with time. For higher damping values, simple pendulum comes to rest or equilibrium position quickly.
The final output animation of motion of the simple pendulum for different damping coefficients can be seen in the following links
1. When damping coefficient (b) = 0.05; https://youtu.be/UU5ev7lpC1g
2. When damping coefficient (b) = 0.1; https://youtu.be/d1Po5t3AuhQ
3. When damping coefficient (b) = 0.2; https://youtu.be/G83mfrFHukw
4. When damping coefficient (b) = 0.3; https://youtu.be/cCWtq-n484I
5. When damping coefficient (b) = 0.4; https://youtu.be/oxtycbPdNvU
6. When damping coefficient (b) = 0.5; https://youtu.be/-g2FJcS76_8
ERRORS:
No major errors has encountered in the program
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
RANKINE CYCLE SIMULATOR
OBJECTIVES: 1. To calculate the state points of the Rankine Cycle based on user inputs. 2. To plot corresponding T-s and h-s Diagrams. INTRODUCTION TO RANKINE CYCLE: The Rankine cycle or Rankine Vapor Cycle is the process widely used by power plants such as coal-fired power plants or nuclear…
12 Apr 2021 08:54 PM IST
PARSING NASA THERMODYNAMIC DATA
OBJECTIVES: 1. To write a function that extracts the 14 temperature co-efficients and calculate properties like molecular weight, enthalpy, entropy and specific heats for all the species in the given data file. 2. to plot the and save enthalpy, entropy and specific heats for the local temperature range spacific…
07 Apr 2021 10:23 AM IST
GENETIC ALGORITHM TO OPTIMISE THE STALAGMITE FUNCTION
OBJECTIVE: To optimise the stalagmite function and find the global maxima of the function. INTRODUCTION: Optimization is the process of making something better. It refers to finding the values of inputs in such a way that the 'best' output values are obtained. The definition of 'best' varies from problem…
01 Apr 2021 10:43 AM IST
CURVE FITTING USING MATLAB
OBJECTIVES: 1. To write codes for linear and cubic polynomial fit for given Cp data. 2. To plot the linear and cubic fit curves along with the raw data points. 3. To write a code to show splitwise method. 4. To measure the fitness characteristics for both the curves. CURVE FITTING: Curve fitting is one of the most…
28 Mar 2021 09:23 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.