All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim: To solves the ODE which represents the equation of motion of a simple pendulum with damping. Objective: To write a program that solves the following ODE which represents the equation of motion of a simple pendulum with damping and create an animated video of output obtains by solving this ODE. Theory:…
Shubhranshu Mishra
updated on 03 Jul 2020
Aim: To solves the ODE which represents the equation of motion of a simple pendulum with damping.
Objective:
To write a program that solves the following ODE which represents the equation of motion of a simple pendulum with damping and create an animated video of output obtains by solving this ODE.
Theory:
The motion of a simple pendulum is a basic classical example of simple harmonic motion, consisting of a small bob and a massless string. Movement of the pendulum depends on Newton's second law. When this law is written down, a second-order Ordinary Differential Equation is formed that describes the position of the end of the pendulum w.r.t time.
fig: Simple Pendulum (with FBD)
Equation of motion is:
In the above equation,
Since the given function is in the second-order differential equation we will convert it into first order to solve the ODE.
Let
θ=θ1
dθ1/dt=θ2
dθ^2/dt^2=dθ2/dt
Input :
Code:
%program to simulate the transient behaviour of a simple pendulum
clear all
close all
clc
%inputs
b = 0.05;
g = 9.81;
l = 1;
m = 1;
% initial condition
theta_0 = [0;3];
% time points
t_span = linspace(0,20,500);
% solve ODE
[t, results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span, theta_0);
% ploting
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel('Plot')
xlabel('Time in sec')
% Iteration using for loop to create animation of simple pendulum
ct=1;
theta_1 = results(:,1);
for i= 1:length(results(:,1))
% initial co-ordinates
x_start= 0;
y_start= 0;
theta_2 = theta_1(i);
% final co-ordinates
x_end = 1*sin(theta_2);
y_end = -1*cos(theta_2);
% ploting for animation
figure(2)
% base of pendulum
plot([-1,1],[0,0], 'linewidth',4,'color','black')
hold on
% string of pendulum
line([x_start x_end],[y_start y_end],'linewidth',6,'color','b')
hold on
% bob of pendulum
plot(x_end,y_end,'marker','o','markersize', 28,'markerfacecolor','r')
axis([-2 2 -2 2])
pause(0.03)
hold off
M(ct)=getframe(gcf);
ct=ct+1;
end
% creating movie from captured frames
movie(M)
videofile = VideoWriter('simple_pendulum.avi','uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
Code for Function program:
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
Detail explanation each step of the program:
1. In the first step Input and initial condition of a simple pendulum are fed.
2. Then the program is written to solve the ODE in which Matlab inbuilt function (ode45) is used with constant theta, t, and another function is used, which is defined separately in function program.
3. In the next step result of solved ODE is plotted w.r.t time using plot command.
4. Now iteration of co-ordinate is fed using for loop to create animation.
5. Then plot command is used to plot pendulum string and bob.
6. In the next step, the move command is used to create an animated video of the oscillating pendulum.
Output:
1. The output obtained is graphical representation velocity curve and displacement curve w.r.t Time.
Various Error faced during programing are followed:
1. Spelling mistake in writing function program.
By correcting spelling mistakes from the function program by reviewing each line of the program.
2. Typing mistake in plotting Bob of the pendulum.
By replacing "o" to "0" (Zero) in, plot(x_end,y_end,'marker','o','markersize', 28,'markerfacecolor','r') command.
3. The pendulum starts oscillating in an inverted direction in an animated video.
The final co-ordinate, y_end = 1*cos(theta_2 ) changed to y_end = -1*cos(theta_2 )
Conclusion:
The simulation of the transient behavior of a simple pendulum is successfully created by using a program in MATLAB.
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...
Frequency Analysis of a rotating shaft (Finite Element Analysis using SolidWorks)
Aim- The aim of this project is to perform a frequency analysis on a rotating shaft, from there we need to determine the critical frequencies and the mode shapes. 5 Mode Shapes were simulated and analyzed. Introduction:- Frequency is the number of occurrences of a repeating event per unit of time. The formula…
06 Jul 2020 03:57 PM IST
Project - Rankine cycle Simulator (MATLAB)
AIM: To create a basic 'RANKINE CYCLE SIMULATOR'. THEORY: The Rankine cycle is the fundamental operating cycle of all power plants where an operating fluid is continuously evaporated and condensed. The selection of operating fluid depends mainly on the available temperature range. The above figure shows us the basic rankine…
03 Jul 2020 10:43 AM IST
Curve fitting (MATLAB)
AIM: To write a program to fit a linear and cubic polynomial for the specific heat data set then calculate the goodness of fit using different parameters and different ways to improve the fit in MATLAB THEORY: Curve fitting is the process of constructing a curve or mathematical function that best fits the data points,…
03 Jul 2020 10:24 AM IST
Solving second order ODEs (MATLAB)
Aim: To solves the ODE which represents the equation of motion of a simple pendulum with damping. Objective: To write a program that solves the following ODE which represents the equation of motion of a simple pendulum with damping and create an animated video of output obtains by solving this ODE. Theory:…
03 Jul 2020 10:20 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.