All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim: To create a program in Matlab to solve the second order ODE of motion of a simple pendulum with damping. OBJECTIVE: To write a program to simulate the transient behavior of a simple pendulum To create an animation of the motion of simple pendulum using MATLAB THEORY : Simple Pendulum – A simple…
Omkar Kudalkar
updated on 07 Jan 2021
Aim: To create a program in Matlab to solve the second order ODE of motion of a simple pendulum with damping.
OBJECTIVE:
THEORY :
Simple Pendulum –
A simple pendulum is defined to have an object that has small mass, also known as pendulum bob, which is suspended from light wire or string, such as shown in fig below.
The Dynamic behavior of pendulum bob is important to understand the motion of simple pendulum. When bob is given simple push while it is at rest ,it experiences sideways force. it is displaced from its equilibrium position and start to oscillate about pivot point swinging back and forth . in general the motion of a simple pendulum is considered to be simple harmonic motion with constant amplitude and is given by equation,
d2θdt2+glsin〖θ=0〗
Where,
θ= Angular displacement of the pendulum bob;
g= Acceleration due to gravity m/s2
l= Length of the pendulum in m.
In practice ,the motion of simple pendulum is subjected to a restoring force along with the friction and air drag which reduces their amplitude of swing with time and bring it back towards the equilibrium position. When the motion of an oscillator reduced due to external force ,the oscillator and its motion is said to be damped .These periodic motion of gradually decreasing amplitude are damped simple harmonic motion .In the damped simple harmonic motion ,the energy of the oscillator dissipates continuously. But for small damping ,the oscillation remain approximately periodic. The differential equation for the motion of a simple pendulum with damping is as follows,
d2θdt2+bm(dθdt)+glsinθ=0
Where,
b= damping coefficient .
m= mass of the pendulum bob in kg.
This differential equation is of order ‘2’ and thus is called as Second Order differential Equation (ODE) for a simple pendulum. By using this equation we can simulate the transient behavior of a simple pendulum using Matlab.
Derivation for code simplification –
Let angular displacement θ=θ1 and angular velocity will be,
dθdt=〖dθ〗1dt=θ2 …………………..Equation NO.1
d2θ〖dt〗2=d2θ〖dt〗2=ddt(〖dθ〗1dt)=dθ2dt ....…………….Equation NO.2
Substituting these in second order for a simple pendulum ,we get,
d2θ〖dt〗2+bmdθdt+glsin〖θ=0〗
d2θ〖dt〗2+bm(〖dθ〗1dt)+glsin〖θ1=0〗
dθ2dt+bmθ2+glsin〖θ1=0〗
This is first order differential equation ,hence we can write,
〖dθ〗1dt=〖θ〗2
dθ2dt=-bmθ2-glsin〖θ1=0〗
Writing the equation in the form of matrix, we have
ddt[■(θ1∘θ2)]=[■(θ2∘-bmθ2-glsin〖θ1〗)]
Where,
θ1= Angular Displacement of the pendulum bob;
θ2= Angular Velocity of the pendulum bob.
BY Solving the above equation in Matlab,we can get the value for Angular Displacement & Angular Velocity with respect to Time.
MATLAB Program :
Inputs : The value of the Pendulum "l" is taken as 1m, mass of the pendulum bob "m" is taken as 1 kg and the damping coefficient "b" is taken as 0.05 the motion of simple pendulum is simulated between time span of 0-20 sec,for Angular displacement "θ1 "= 0, Angular velocity "θ2" = 3 rad/sec at time =0`
% Second order ODE of a simple Pendulum and its Animation
clear all
close all
clc
%Inputs
b = 0.05;
g = 9.81;
l = 1 ;
m = 1;
% Initial condition
theta_0 = [ 0 ; 3 ];
%Time span
t_span = linspace(0,20,100)
%Solving ODE
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
% Plotting Angular displacement and Angular velocity w.r.to Time
figure (1)
hold on
plot(t,results(:,1))
plot(t,results(:,2))
title('Damped Harmonic motion of a Pendulum')
legend('Angular displacement','Angular velocity')
xlabel('Plot')
ylabel('Time(seconds)')
% For Loop
% Before starting the for Loop , a counter value was defined
ct = 1 ;
for i = 1:length(results(:,1))
x_start = 0
y_start = 0
x_end = 1*sin(results(i,1))
y_end = -1*cos(results(i,1))
%Plotting the animation
figure (2)
plot([-1 1],[0 0], 'linew',3)
hold on
plot([x_start x_end],[y_start y_end],'linew',3)
hold on
plot(x_end,y_end,'o','markersize',20,'markerfacecolor','y')
title('Animation of transient behaviour of a pendulum')
axis([-1.5 1.5 -1.5 1])
pause(0.03)
hold off
M(ct) = getframe(gcf)
ct = ct + 1
end
%Animation of the Pendulum
movie(M)
videofile=VideoWriter('Pendulum Animation.avi','uncompressed avi')
open(videofile)
writeVideo(videofile,M)
close(videofile)
Code explained:
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
%Solving ODE
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
Ode45
[ t , results] = Ode45 ( Odefun , t_span ,y0 )
Input :
results = [t,results ] contains the results which we need to plot with respect to time in which result_1 contain Angular displacement & result_2 contain Angular velocity bothjs value in radian,by using this we can calculate different value of angular displacement and angular velocity with respect to time
Odefun is a function handle of the differential equation 1st thing to go inside Ode45 solver
EX : Odefun = @( t , y ) – 0.5*y ;
Odefun must have “ t” & “ y” inputs even if only one argument is used in the differential equation.
Where, “ t” is ( 1 x 1) for the dependent variable and “ y “ is ( m x 1) the dependent variable
t_span = [ t0 t1 t2 … tf ]
Output :
t = numerical method evaluated point , returned as column vector ( n x 1 )
y = numerical solution array ( n x m ) ,each row in y the solution at corresponding row of t.
ODE45 can only solve 1st order ODE …!
Ode is based on an explicit Rung-Kutta ( 4, 5 ) formula, the Dormand –Prince pair.
Higher order ODEs can be reduced to system of coupled 1st order Odes in state variable form .
Plotting of graph
% Plotting Angular displacement and Angular velocity w.r.to Time
figure (1)
hold on
plot(t,results(:,1))
plot(t,results(:,2))
title('Damped Harmonic motion of a Pendulum')
legend('Angular displacement','Angular velocity')
xlabel('Plot')
ylabel('Time(seconds)')
% For Loop
% Before starting the for Loop , a counter value was defined
ct = 1 ;
for i = 1:length(results(:,1))
x_start = 0
y_start = 0
x_end = 1*sin(results(i,1))
y_end = -1*cos(results(i,1))
%Plotting the animation
figure (2)
plot([-1 1],[0 0], 'linew',3)
hold on
plot([x_start x_end],[y_start y_end],'linew',3)
hold on
plot(x_end,y_end,'o','markersize',20,'markerfacecolor','y')
title('Animation of transient behaviour of a pendulum')
axis([-1.5 1.5 -1.5 1])
pause(0.03)
hold off
M(ct) = getframe(gcf)
ct = ct + 1
end
Program Output :
Conclusion :
2. From the animation of the motion of simple pendulum , it can be concluded that , as the damping coefficient is increased, the motion of the pendulum reduces correspondingly and approaches the equilibrium position .Also increase in damping coefficient reduced th time taken by the pendulum to reach its equilibrium position .
ANIMATION :
Referance Link :
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...
Week 1 Understanding Different Battery Chemistry
Abstract: The Lithium-ion battery is one of the most common batteries used in Electric Vehicles (EVs) due to the specific features of high energy density, power density, long life span and environment friendly. With the development of lithium-ion battery technology, different materials have been adopted in the design of…
14 Dec 2021 02:03 AM IST
Week 8 Challenge:Thermal Management
Abstract: Control functionality of modern vehicles is getting more and more complex. Programming complex embedded systems involves reasoning through intricate system interactions along paths between sensors, actuators and control processors. This is a time-consuming and error-prone process. Furthermore, the…
30 Sep 2021 05:06 AM IST
UML (Unified Modeling Language) high-level schematic of a remote controller toy car system.
Abstract: Control functionality of modern vehicles is getting more and more complex. Programming complex embedded systems involves reasoning through intricate system interactions along paths between sensors, actuators and control processors. This is a time-consuming and error-prone process. Furthermore, the resulting…
30 Sep 2021 04:45 AM IST
Explain the cooling technologies of a power converter And Calculation of MOSFET Thermal Resistance and Power Dissipation.
Explain the cooling technologies of a power converter? Abstract: Power electronics devices such as MOSFETs, GTOs, IGBTs, IGCTs etc. are now widely used to efficiently deliver electrical power in home electronics, industrial drives, telecommunication, transport, electric grid and numerous other applications.…
30 Sep 2021 04:41 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.