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 motion of a simple pendulum by solving the ordinary differential equation of motion of the pendulum. Governing equation: d2θdt2+(bm)dθdt+gLsinθ=0 this is the ode for the motion of a simple pendulum with a damping effect. Procedure: First, define the function to…
Bharath Gaddameedi
updated on 24 Feb 2022
Aim: To simulate the motion of a simple pendulum by solving the ordinary differential equation of motion of the pendulum.
Governing equation: d2θdt2+(bm)dθdt+gLsinθ=0
this is the ode for the motion of a simple pendulum with a damping effect.
Procedure:
Code:
close all
clear all
clc
%solving some ode
t = linspace(0,20,500); %starting time and ending time
y0 =[0 3]; %initial condition
[t y] = ode45('odefun',t,y0);
%plotting of angular velocity and displacement
plot(t,y(:,1),'color','b')
hold on
plot(t,y(:,2),'color','r')
ylabel('angular velocity and displacement')
xlabel('time')
hold off
% Pendulum Animation
ct=1;
for i=1:length(y(:,1))
x0 = 0;
y0 = 0;
x1 =1*sin(y(i,1));
y1 =-(1*cos(y(i,1)));
figure(2)
plot([-1,1],[0,0],'linewidth',3,'color','b');
hold on
plot([x0 x1], [y0 y1],'linewidth',3,'color','k');
hold off
hold on
plot(x1,y1,'o','markersize',20,'markerfacecolor','r','markeredgecolor','r');
hold off
title('Simulation of a Damped Pendulum Motion');
grid on
axis([-1.5 1.5 -1.5 .5]);
M(ct)=getframe(gcf);
ct = ct + 1;
end
% Video of the animation
movie(M)
video=VideoWriter('Pendulum.avi','Uncompressed AVI');
open(video)
writeVideo(video,M)
close(video)
Function code
function [ydot] = odefun(t,y)
l =1;
m = 1;
b=0.05;
g =9.81;
ydot = zeros(2,1);
ydot(1)=y(2);
ydot(2) = -(b/m) * y(2)-(g/l) * sin(y(1));
end
Results:
plot:
Animation:
In the plot, The red plot is for Velocity vs time and the other one displacement and time. The plots vary with the damping factor.
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- Mixing Tee
…
08 Jul 2023 06:07 PM IST
Week 2 Challenge : Surface meshing on a Pressure valve
Surface meshing on a Pressure valve Aim: Check the geometrical errors on the pressure valve and perform topology cleanup. Meshing it for three target lengths. Objectives: Mesh it for target lengths 1mm, 3mm, and 5mm.…
10 Apr 2023 03:12 AM IST
Week 7 - Simulation of a 1D Super-sonic nozzle flow simulation using Macormack Method
Simulation of a 1D Super-sonic nozzle flow simulation using Macormack Method Aim: To simulate the isoentropic flow through a quasi 1D subsonic-supersonic nozzle using conservation and non-conservation forms of governing…
19 Dec 2022 08:52 AM 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.