All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim - To solve the second-order ODE function for a pendulum by using Matlab and simulate the motion. Theory for pendulum A pendulum is a mass attached with a string suspended from a pivot so that it can swing freely. It is subjected to a restoring force which accelerated it back to normal in an equilibrium…
Siddharth jain
updated on 10 Feb 2021
Aim - To solve the second-order ODE function for a pendulum by using Matlab and simulate the motion.
Theory for pendulum
A pendulum is a mass attached with a string suspended from a pivot so that it can swing freely. It is subjected to a restoring force which accelerated it back to normal in an equilibrium position, the movement of back and forth of motion of a pendulum is known as a period. The pendulum oscillates freely from its suspension. The motion that we see in the pendulum is totally dependent on the length of the string and the initial angular displacement provided.
Fig(a) nomenclature of pendulum fig(b) swing positions
The real pendulum works on the principle of 'NEWTONS SECOND LAW OF MOTION', where the pendulum is subjected to friction and air drag which reduces the amplitude and motion of string cycle by cycle. According to newtons second law, it states that "the rate of change of the momentum of the body with time is directly proportional to the force applied and bring back to the position where the force is applied on it i.e in the direction from where the force is applied, this is why the body produces a proportional acceleration.
F = m*a
where,
F= force (N)
m= mass
a= acceleration
Objective -
(a) Write a program to solve the ODE which represents the equation of motion of a simple pendulum with damping.
following is the ODE about a simple pendulum.
where,
g = gravity in m/s^2,
L = length of the pendulum in m,
m = mass of the ball in kg,
b= damping coefficient.
(B) simulate the motion of pendulum body
Here, To solve the ODE, we assign the value of the input which are given to the pendulum.
L=1 metre,
m=1 kg,
b=0.05.
g=9.81 m/s^2.
time period(t_span) = 0-20 sec
angular displacement=0
angular velocity=3 rad/sec at time t=0.
Procedures
To calculate the second-order oDE, we need to break it into first order for coding and calculation purposes and then form a solution matrix for results.
MATLAB CODE
%breaking second order ode and form solution matrix
%Defining function
function [dtheta_dt] = pend_func(t,theta,b,g,l,m);
theta1 = theta(1);
theta2 = theta(2);
dtheta1_dt = theta(2);
dtheta2_dt = (-b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt = [dtheta1_dt;dtheta2_dt];
end
In this function, the simplified second order ode by simplifying theta1 and theta2. the respective value of theta1 and theta2 are assigned and differentiated it and putting all the values together in the solution matrix.
2) created the main function script and specify all the values or parameters, the initial time span and condition is defined. The inbuilt Matlab solver named 'ode45' is used to solve the function. This function implements the Runge-Kutta method with a variable time step for efficient computation with minimum error propagation.
clear all
close all
clc
%input conditions
b = 0.05;
g = 9.81;
l = 1;
m = 1;
% initial conditions
theta_0 = [0;3];
%time point
t_span = linspace(0,20,300);
%solve ode
[t,results] = ode45(@(t,theta) pend_func(t,theta,b,g,l,m),t_span,theta_0);
Here, in this main function, we used 'linspace' command for time span in order to get results at a various time step, finally, the calculated results are as follow.
Results
3) in this step we will be plotting and labeling the following outcome.
MATLAB CODE
%plotting figure(1)
title('Relationship Between Angular Displacement And Angular Velocity w.r.t. Time')
hold on
plot(t,results(:,1))
plot(t,results(:,2))
grid on
xlabel('time(sec)')
legend('Angular Displacement(rad)','Angular Velocity(rad/sec)')
Results
observing the above result we can conclude is that the angular displacement w.r.t angular velocity is changing, certainly, both are decreasing w.r.t time as inclusion of damping at pivot point
% to plot and animate pendulum
ct=1
for i = 1:length(results(:,1));
% co-ordinates
x0 = 0
y0 = 0
x1 = l*sin(results(i,1));
y1 = -l*cos(results(i,1));
figure (2)
plot([-1 1],[0 0],'linewidth',3,'color','r')
axis([-3 3 -3 3])
hold on
plot([x0 x1],[y0 y1],'linewidth',3,'color','g')
plot([x0 x1],[y0 y1],'o','Markersize',15,'MarkerFaceColor','r','MarkerEdgeColor','r')
grid on
pause (0.01)
M(ct) = getframe(gcf)
hold off
ct = ct+1;
end
%movie commands
movie(M)
video_file = VideoWriter('pendulum_challenge.avi','uncompressed AVI')
open(video_file)
writeVideo(video_file,M)
close(video_file)
result
Animation
The following will be the youtube link of animation of a simple pendulum.
https://www.youtube.com/watch?v=6WwDRyvP0-c
error occurred
hold on retains the current plot and certain axes properties so that subsequent graphing commands add to the existing graph.
to overcome this problem I use the hold-off command because sets axis properties to their defaults before drawing new plots. and after using the hold-off command the error that occurred is corrected.
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 5 - Rayleigh Taylor Instability
Aim: To perform Rayleigh-Taylor instability CFD simulation. Objectives: 1. To develop a numerical case set-up for Rayleigh-Taylor instability problem in Ansys Fluent. 2. To conduct grid dependency test to understand the variation in RT instabilites. 3. To understand the effect on RT instabilities due to variation…
20 Jan 2022 08:26 AM IST
Week 4 - CHT Analysis on Exhaust port
Aim: To develop a numerical set-up for conjugate heat transfer analysis on exhaust port. Objectives: 1. Investigate wall adjacent and surface heat transfer coefficients. 2. Understand flow and thermal characteristics. 3. To perform mesh independent study. 4. Set-up a rough surface model to understand…
20 Jan 2022 08:24 AM IST
Week 3 - External flow simulation over an Ahmed body.
Aim: To simulate external flow over an Ahmed body using Ansys fluent. Objectives: 1. To set-up simulation case for velocity of 25 ms with working fluid as air. 2. Simulate various cases with different Y+ values (coarse, medium and refined mesh at the boundary). 3. Calculate drag and…
19 Jul 2021 03:20 PM IST
Week 2 - Flow over a Cylinder.
Aim: To simulate flow past a cylinder with varying Reynolds number and interpret the flow characteristics. Objectives: 1. Simulate the steady and unsteady (transient) cases for range of Reynolds number. 2. To calculate the drag and lift coefficients for the respective cases. 3. To calculate strouhal number for unsteady…
11 Jun 2021 03:02 PM 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.