Simulating the transient behaviour of a simple pendulum using MATLAB
AIM: To simulate the transient behaviour of a simple pendulum using MATLAB
OBJECTIVE:
- To generate a plot describing the transient behaviour of the simple pendulum
- To create a GIF describing the animated motion of the simple pendulum
INTRODUCTION
A simple pendulum is defined to have an object that has a small mass, also known as the pendulum bob, which is suspended from a light wire or string.
It is an idealized mathematical model of a pendulum. This is a weight (or bob) on the end of a massless cord suspended from a pivot, without friction. When given an initial push, it will swing back and forth at a constant amplitude. Real pendulums are subject to friction and air drag, so the amplitude of their swing’s declines.
APPLICATIONS
- Clock
- Car Shock Absorbers
- Musical Instruments
- Bungee Jumping
- Diving Board
- The Process of Hearing
- Earthquake-proof buildings
- Metronome
FORMULA
`[(d^2theta)/dt^2] + [b/m][(d theta)/dt]+[g/L]sintheta = 0`
where
- b - damping coefficient
- l - Length of the string
- g - acceleration due to gravity
- m - the mass of the bob
The above equation is a second-order differential equation(ODE). So, it must be divided into two first-order differential equations.
They are as follows:-
- `(d theta_1)/dt = theta_2`
- `(d theta_2)/dt = -[b/m]theta_2 - (g/l)sin theta_1`
The following conditions are assumed during the conversion:-
- `theta = theta_1`
- `(d theta)/dt = (d theta_1)/dt = theta_2`
- `(d^2 theta)/dt^2 = d/dt[(d theta_1)/dt] = (d theta_2)/dt`
PROGRAM CODE
User-defined function
%A user defined function to generate the solution vector.
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
Main program code
%Program for simulating the transient behaviour of a simple pendulum
%using a second order ODE solver
clear all
close all
clc
%Input Parameters
l=1;
m=1;
b=0.05;
g=9.81;
%Initial condition
theta_0=[0;2.5];
%Time array
T_span=linspace(0,20,300);
%Solving the ODE
[t,results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m),T_span,theta_0);
plot(t,results(:,1),'black')
grid on;
hold on;
title('Transient behaviour of a simple pendulum')
plot(t,results(:,2),'red')
legend({'Displacement','Velocity'},'Location','southeast')
xlabel('Time')
ylabel('Plot')
%Animation depicting motion of the pendulum
ct=1;
figure(2)
for i=1:length(t)
x0=0;
y0=0;
x(i)=l*sin(results(i,1));
y(i)=-l*cos(results(i,1));
plot([-2 2],[0 0],'linewidth',1)
line([x0 x(i)],[y0 y(i)],'linewidth',1)
hold on
plot(x(i),y(i),'-O','markers',15,'markerfacecolor','r')
title('Animation depicting motion of the pendulum')
hold off
grid on
axis([-2 2 -2 2])
pause(0.04)
M(ct)=getframe(gcf);
ct=ct+1;
end
movie(M)
Videofile=VideoWriter('Simple Pendulum.avi');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)
Procedure
- Import neccesary modules for using built in callable functions for solving the ODE and plotting the graph.
- Divide higher-order ODE into the first-order ODE and define in the function.
- Define the initial conditions and angular velocity and displacement. The simulation time is taken in the range of 0-20 seconds.
- The ODE is solved and the graph is plotted.
- An animated video depicting the motion of the simple pendulum is generated.
RESULTS AND OBSERVATIONS
CONCLUSION
Using the code above, we were able to succesfully generate a plot depicting the transient nature of the simple pendulum and also able to generate an animated video depicting the motion of the pendulum