All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim:To simulate the transient behaviour of a simple pendulum and to create an animation of it's motion. THEORY: A simple pendulum consists of a mass m,hanging to a string…
Sumanth Shetty
updated on 12 Feb 2020
Aim:To simulate the transient behaviour of a simple pendulum and to create an animation of it's motion.
THEORY:
A simple pendulum consists of a mass m,hanging to a string of length L,to a fixed point having damping co-efficient b.
The ordinary differrential eequation for the motion of simple pendulum is,
d2θdt2+(bm)dθdt+(gL)sinθ=0d2θdt2+(bm)dθdt+(gL)sinθ=0
where b= Damping co-efficient
m=mass
g=Acccelaration due to gravity i.e.,9.81m/s^2
L= length of the simple pendulum
To solve this second order ODE,we split the equation into first order ODEs
given,
d2θdt2+(bm)dθdt+(gL)sinθ=0d2θdt2+(bm)dθdt+(gL)sinθ=0 ...(eq.1)
let,
θ=θ1θ=θ1
then,
dθdt=dθ1dtdθdt=dθ1dt
&
θ2=dθ1dtθ2=dθ1dt ...(eq.2)
then eq.1 becomes
dθ2dt+(bm)θ2+(gL)sinθ1=0dθ2dt+(bm)θ2+(gL)sinθ1=0
so, dθ2dt=-(bm)θ2-(gL)sinθ1dθ2dt=−(bm)θ2−(gL)sinθ1 ...(eq.3)
we can also write (eq.2) and (eq.3) as
ddt[θ1θ2]=[θ2-(bm)θ2-(gL)sinθ1] ...(eq.4)
Now the (eq.4) is modified in to a matrix form.
Code explanation:
the constants dampping co-efficient,length of the string,accelaration due to gravity & massses are entered
%inputs
b=0.05;
m=1;
l=1;
g=9.81;
theta is entered as a column matrix & time span is entered using linspace command
%initial conditions
theta_0=[0;3];
%time span
t_span=linspace(0,20,200);
To solve ODEs in matlab, a solver called ode45 is used,where the ode45 gets the values such as time span ,theta_0 & define it into the user defined function and returns it into [t,results]
[t,results]=ode45(@(t,theta)ode_function(t,theta,b,m,l,g),t_span,theta_0);
Then the results are plottted to get the transient behaviour of the pendulum motion.
figure(1)
hold on
plot(t,results(:,1))
plot(t,results(:,2))
xlabel('time span')
ylabel('Theta')
legend('Angular displacement','Angular velocity')
then the equation is solved with vertical to get the variables required for animation.
By solving the starting point & end point of the string,we get
x0=0
y0=0
x1=lsinθ
y1=lcosθ
Then 'for' loop is used to plot the displacement of the pendulum at various angles of θ
A counter variable 'ct' is used to get every frame of displacement using 'getframe' command.
ct=1;
for i=1:length(t)
x0=0;
y0=0;
x1=-l*sin(results(i,1));
y1=-l*cos(results(i,1));
figure(2)
plot([x0,x1],[y0,y1],'linewidth',2)
hold on
line([-1 1],[0 0])
plot(x1,y1,'.','MarkerSize',50)
hold off
axis([-1 1 -1 1])
M(ct)=getframe(gcf);
ct=ct+1;
end
To create a video file, 'movie' commands are used.
movie(M)
videofile=VideoWriter('Pendulum_ODE.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Errors & Error optimization:
Used 'hold on 'command before plotting the graphs
hold on
plot([x0,x1],[y0,y1],'linewidth',2)
line([-1 1],[0 0])
plot(x1,y1,'.','MarkerSize',50)
hold off
error resulted was
This error was optimized by using 'hold on' command after the first plot.
CODING:
%Animation of a 2nd ODE equation
clear all
close all
clc
%inputs
b=0.05;
m=1;
l=1;
g=9.81;
%initial conditions
theta_0=[0;3];
%time span
t_span=linspace(0,20,200);
%solving ODE
[t,results]=ode45(@(t,theta)ode_function(t,theta,b,m,l,g),t_span,theta_0);
%plotting
figure(1)
hold on
plot(t,results(:,1))
plot(t,results(:,2))
xlabel('time span')
ylabel('Theta')
legend('Angular displacement','Angular velocity')
%animation
%counter variable
ct=1;
for i=1:length(t)
x0=0;
y0=0;
x1=-l*sin(results(i,1));
y1=-l*cos(results(i,1));
%plotting
figure(2)
plot([x0,x1],[y0,y1],'linewidth',2)
hold on
line([-1 1],[0 0])
plot(x1,y1,'.','MarkerSize',50)
hold off
axis([-1 1 -1 1])
%getting frames
M(ct)=getframe(gcf);
ct=ct+1;
end
%animation of the motion
movie(M)
videofile=VideoWriter('Pendulum_ODE.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Function ode_function,
function [result_matrix]=ode_function(t,theta,b,m,l,g)
%initializing the values
theta1=theta(1);
theta2=theta(2);
dtheta1=theta2;
dtheta2=(-b/m)*theta2-(g/l)*sin(theta1);
% resultant matrix
result_matrix=[dtheta1;dtheta2];
end
CONCLUSION:
The Transient behaviour of the 2nd order ODE is:
The animation of the 2nd order simple pendulum ODE is as below
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 - 3 Drop test Challenge
Objective: To simulate crash test for a mobile phone. Procedure: 1.Meshed model is imported in to LS-Dyna. 2.We need to define cards for the model. Cards needed to create are Part Material section contact interface Initial velocity Output requests 3.We need to define the material card for both mobile phone and rigid…
06 Mar 2021 10:13 AM IST
Side crash analysis of Neon Dodge BIW
Objective: To analyse the side crash of a Neon car's BIW as per Federal Motor Vehicle Safety Standard 214 (FMVSS214). Abstract: The results of a study on the response of a side impact beam located in a car door to impact loading is presented. The side impact beam is situated in both the front and rear…
10 Feb 2021 12:22 PM IST
Frontal crash analysis of Neon Dodge BIW
Objective: To analyse the frontal crash of a car's BIW as per the FMVSS(Federal Motor Vehicle SafetyStandard ).208 Abstract: Every year National Highway Traffic Safety Administration evaluates crash safety for cars all around the world.Tests are conducted to measure how people inside the car are…
10 Feb 2021 12:22 PM IST
Design of an Electric Vehicle using MATLAB and Simulink
Abstarct: An electric vehicle is a vehicle that uses one or more electric motors or traction motors for propulsion.An electric vehicle may be powered through a collecter system by electricity from off vehicle sources or may be self contained with a battery,solar panels,fuel cells or an electric generator to convert fuel…
10 Feb 2021 12:20 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.