All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Report : Simple Pendulum Simulation by solving second order ODE . . The objective of this program is to simulate a simple pendulum by solving second…
Aadil Shaikh
updated on 22 Jan 2020
Report :
Simple Pendulum Simulation by solving second order ODE .
.
b = damping Co-efficient
g = gravity m/s^2
L = length of string in (m)
m = mass of ball (kg)
d(θ1)dt=θ2 & d(θ2)dt=−bm⋅θ2−glsin⋅θ1
clear all
close all
clc
% input parameters
b = 0.05;
l = 1;
g = 9.81;
m = 1;
%displacement and velocity column wise
theta_0 = [0;3];
% time span 0-20 sec , 500 values in between
t_span = linspace(0,20,500);
% using ode45 command to solve second order ODE
[t , results] = ode45(@(t , theta) pendufunc(t,theta,b,g,l,m),t_span,theta_0);
% plotting time vs displacement & time vs angular velocity
subplot(5,4, [13, 14, 17 ,18])
plot(t,results(:,1))
hold on
plot(t,results(:,2))
hold off
subplot(5,4,[15 16 19 20])
plot(results(:,1),results(:,2))
xlabel('Position (rad)')
ylabel('Angular velocity')
ct = 1;
% for loop to run the loop for simple pendulum angles for different values in time
for i = 1:length(results(:,1))
x0 = 0;
y0 = 0;
x1 = -l*sin(results(i,1));
y1 = -l*cos(results(i,1));
subplot(5,4,[1 2 3 4 5 6 7 8 9 10 11 12]);
% plotting the rigid base
plot([-1 1] ,[ 0 0] , 'linewidth' ,2,'color','g');
hold on
% plotting string
line([x0 x1] , [y0 y1], 'linewidth',1,'color','[0.5 0.5 0.5');
hold on ;
% plotting the mass
plot(x1,y1,'o' ,'markers',20,'markerfacecolor','[ 0.5 1 1]');
r = 0.25;
rectangle('position', [(x1 -r/2), (y1 -r/2 ),r,r],'curvature',[1 1] ,'facecolor','g','linewidth',3)
hold on
axis equal
grid on
axis ([-1.5 1.5 -1.5 0.5])
pause(0.003);
hold off
M(ct) = getframe(gcf);
ct = ct+1;
end
% movie making
movie(M)
videofile = VideoWriter('simple_pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation of code:
function [dtheta_dt] = pendufunc(t,theta,b,g,l,m)
theta1 = theta(1);
theta2 = theta(2);
% two first order ODE
dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2 - (g/l)*sin(theta1);
%clubbing them together
dtheta_dt = [dtheta1_dt; dtheta2_dt];
end
END
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...
Flow over a Throttle body - Using CONVERGE CFD
I. Introduction: In this Project, A Steady & Transient state simulation is done of a Flow through an Elbow joint consisting of a throttle valve. The steady state case is solved with the Throttle valve fully open until convergence is reached. While the Transient case is ran with the throttle valve rotating i.e…
18 Sep 2020 08:29 PM IST
Literature review – RANS Derivation and analysis
Introduction: The Reynolds-averaged Navier–Stokes equations (or RANS equations) are time-averaged equations of motion for fluid flow. The idea behind the equations is Reynolds decomposition, whereby an instantaneous quantity is decomposed into its time-averaged and fluctuating quantities,…
18 Sep 2020 08:28 PM IST
C.H.T Analysis on a Graphic card using ANSYS FLUENT
I. Introduction : In this project, A steady state conjugate heat transfer analysis on a Graphic card model is done. Graphic card has become an everyday used object and a very importat part of any computer system, laptops etc. This product is mass produced daily in millions and has made computers exceptionally efficient.…
18 Sep 2020 08:23 PM IST
Aerodynamics : Flow around the Ahmed Body using ANSYS FLUENT
I. Introduction : Automotive aerodynamics comprises of the study of aerodynamics of road vehicles. Its main goals are reducing drag, minimizing noise emission, improving fuel economy, preventing undesired lift forces and minimising other causes of aerodynamic instability at high speeds. Also, in order to maintain…
18 Sep 2020 08:21 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.