Project

TRANSIENT BEHAVIOR OF SIMPLE PENDULUM

AIM:

To simulate the transient behavior of a damped simple pendulum.

OBJECTIVES:

  • To simulate and create an animation of the motion of the damped simple pendulum.
  • To understand how to solve ordinary differential equations in MATLAB using the function ‘ode45’.

INTRODUCTION:

In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum.

The motion of the pendulum is based on ‘Newton’s second law of motion.’ Solving this equation in MATLAB can help us to know how the function ‘ode45’ works and what are the parameters it require.

Note: We can use the command ‘doc function’ in the command window to know about the function, the parameters it uses, the functionality of it, the output it gives alongwith some examples.

e.g. doc ode45

EQUATIONS USED:

  • `(d^2theta)/dt + b/m (d theta)/dt + g/l sin(theta) = 0`

where b = damping coefficient

m = mass of the bob

g = acceleration due to gravity

l = length of the spring

  • Now, if we assume `theta = theta1` and `(d theta1)/dt = theta2` then solving the ODE in the matrix format as follows:

`d/dt((theta1),(theta2)) = ((theta2),(-b/m theta2-g/l sin(theta1)))`

PROCEDURE OF COMPLETION:

  • All the required parameters were initialized and then were used as parameters for the differentia equation solver ‘ode45’.
  • A function named ‘ode_func’ was defined to define the second order ODE as a function of two first order DE.
  • Then, for the simulation part functions such as ‘VideoWriter’,’getframe’ were used.

The program attached below shows the utilization of the above mentioned points:

%% TRANSIENT BEHAVIOUR OF SIMPLE PENDULUM
% This is a programme to show the transient behaviour of simple pendulum by
% using the second order DE of its motion.
clear all;
close all;
clc;


%% Initialization of parameters
L     = 1;          % length of the pendulum (in m)
m     = 1;          % mass of the bob (in kg)
b     = 0.05;       % damping coefficient
g     = 9.81;       % acceleration due to gravity (in m/s^2)

theta  = [0;3];                % initial parameters of the equation i.e. angular displacement and angular velocity
t_span = linspace(0,20,500);    % the time space for evaluation of the equation      


%% Calculation of the motion using second order DE
[t, results] = ode45(@(t,theta) ode_func(t,theta,L,g,b,m),t_span,theta);


%% Plotting
figure(1),clf
plot(t,results(:,1),'linew',2),hold on
plot(t,results(:,2),'r','linew',2)
grid on
legend('Angular displacement','Angular Velocity')
xlabel('time','fontsize',10)
ylabel('theta','fontsize',10)
title('TRANSIENT BEHAVIOUR OF SIMPLE PENDULUM','fontsize',15)


%% Setting up the movie
movie = VideoWriter('Simple_Pendulum.avi');
open(movie)


%% Using iterations to simulate the mechanism
for j = 1:length(t)
    
    % starting coordinates
    xi = 0;
    yi = 0;
    
    % final coordinates
    xf = L*sin(results(j,1));
    yf = -L*cos(results(j,1));
    
    % plotting
    figure(2),clf
    plot([-1 1],[0 0],'k','linew',3)                             % base   
    hold on
    plot([0 0],[-0.75 0],'b--')
    plot([xi xf],[yi yf],'k','linew',2)                                    % string of pendulum
    plot(xf,yf,'ro','markerfacecolor','g','markersize',20)       % bob of pendulum
    text(-0.5,0.3,['Timer = ' num2str(t(j)) 's'],'fontsize',15)
    text(-0.5,-1.5,['Angular Velocity = ' num2str(results(j,2))],'fontsize',15)
    axis([-1.5 1.5 -2 0.5])
    axis off
    title('SIMPLE PENDULUM','fontsize',20)
    
    
    % writing out movie
    writeVideo(movie,getframe(gcf))
    pause(0.5)
    
end
    
% Closing out the movie    
close(movie)

The function 'ode_func' is as follows:

function [dtheta_dt] = ode_func(t,theta,L,g,b,m)
%% This function will give us two output namely the angular velocity vector and  angular displacement vector
%  which are the solutions of the second order DE of the transient
%  behaviour of the simple pendulum
%                                                                                               
%  INPUTS : 
%           1. t          time vector
%           2. theta      initial conditions of the pendulum
%           3. L          length of the pendulum
%           4. g          acceleration due to gravity
%           5. b          damping coefficient
%           6. m          mass of the bob
%
%  OUTPUTS :
%           1. theta1     displacement vector
%           2. theta2     velocity vector


%% Initialization and calculation of the ODE
    theta1 = theta(1);
    theta2 = theta(2);
    
% Calculation    
    dtheta1_dt = theta2;
    dtheta2_dt = -(b/m)*theta2 - (g/L)*sin(theta1);
    dtheta_dt = [dtheta1_dt; dtheta2_dt];
end

OBSERVATIONS:

The following graph shows the angular displacement and the angular velocity vs time graph of the pendulum under damped conditions:

The simulation of the pendulum can be seen through the following link:

https://youtu.be/PM1YtWwAH2k

CONCLUSION:

The ODEs form an integral part in the field of engineering as many phenomena and motions can be described in the form of ODEs. MATLAB can solve different forms of ODEs which helps us to know about the variables and the graphical representations by these equations can help us analyze a particular scenario in a better way. Also, the creation of simulation in MATLAB also helps us in knowing the behavior of a certain thing under certain conditions which also helps in knowing what can be done to the machine/thing under such circumstances.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.