Project

TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM

AIM: TO SIMULATE THE TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM USING MATLAB/OCTAVE.

OBJECTIVE:

  • To write a program to solve the second order differential equation of motion of the pendulum.
  • To plot the damping of angular displacement and velocity.
  • To Create the Animation file of the pendulum motion.

OVERVIEW:

A pendulum is a body suspended from a fixed support so that it swings freely back and forth under the influence of gravity. When a pendulum is displaced sideways from its resting, equilibrium position, it is subject to a restoring force due to gravity that will accelerate it back toward the equilibrium position. When released, the restoring force acting on the pendulum's mass causes it to oscillate about the equilibrium position.

`(d^2theta)/dt^2+b/m(d theta)/dt+g/lsin theta=0`

Where,

b = damping coefficient(kg/s)

m = mass of the body hanged(kg)

g = acceleration due to gravity (m/s2)

l = length of the wire(m)

let, `theta=theta_1`

and `(d theta)/dt=(d theta_1)/dt=theta_2 ..........eq-1`

`(d^2theta)/dt^2=(d^2theta_1)/dt^2=d/dt((d theta_1)/dt)=d/dt(theta_2).........eq-2`

`(d^2theta)/dt^2+b/m(d theta)/dt+g/lsin theta=0`

`(d^2theta)/dt^2+b/m(d theta_1)/dt+g/lsin theta_1=0`

`(d^2theta)/dt^2+b/m(theta_2)+g/lsin theta_1=0`

`(d theta_1)/dt=theta_2,(d theta_2)/dt=-b/mtheta_2-g/lsintheta_1`

`d/dt[[theta_1],[theta_2]]=[[theta_2],[-b/mtheta_2-g/lsintheta_1]]`

so, `d/dt[theta]=[[theta_2],[-b/mtheta_2-g/lsintheta_1]]`

BODY OF CONTENT:

Firstly, write the program to get the damping behavior :

clear all
close all
clc

%Inputs
b=0.05;
g=9.81;
l=1;
m=0.1;

%Initial condition
theta_0 = [0;5];

%Time points
t_span=linspace(0,10,500);

%solve
[t,results]= ode45(@(t,theta) pendulum_ode_func(t,theta,b,g,l,m),t_span,theta_0);

plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('plot')
ylabel('time')

for pendulum_ode_func , the program is saved as

function [dtheta_dt] = pendulum_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];
  
endfunction

then we got the plot as:

FINAL PROGRAM:

part-1

clear all
close all
clc

%Inputs
b=0.05;
g=9.81;
l=1;
m=0.1;

%Initial condition
theta_0 = [0;5];

%Time points
t_span=linspace(0,20,200);

%solve
[t,results]= ode45(@(t,theta) pendulum_ode_func(t,theta,b,g,l,m),t_span,theta_0);

figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('plot')
ylabel('time')


%Creating Animation
ct=1;

for    i = 1:length(t_span)
  
  
  x0=0;
  y0=0;
  
  x1=l*sin(results(i,1));
  y1=-l*cos(results(i,1));
  
  figure(2)
  %For straight line
  plot([-1 0 1],[0 0],'linewidth',8,'color','g')
  hold on
  
  %For string
  plot([x0 x1],[y0 y1],'linewidth',3,'color','b','marker','o')
  hold on
  
  %For BOB
  plot(x1,y1,'markersize',25,'color','r')
  axis([-2.5 2.5 -2.5 2.5])
  pause(0.03)
  
  hold off
  
  ct=ct+1;
  
  
   %q(ct)=getframe(gcf);
   Text=sprintf("pendulum%d.png",ct);
   saveas(1,Text)
   

  
end
%Movie(q)
%videofile=VideoWriter('Pendulum.avi','Uncompressed AVI');
%open(videofile)
%write(videofile,q)
%close(videofile)

part-2

function [dtheta_dt] = pendulum_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];
  
endfunction

Output:

EXPLANATION OF PROGRAM :

  • In theta_0 , angular displacement and velocity are provided.
  • By ‘hold on’ command, we are combining all the plots to one figure.
  • (: ,1) , explains that the displacement/velocity change start from 0.
  • x0, y0 are provided for the fixed end of the wire.
  • ‘Ode45’ is for calling ODE function.
  • ‘pendulum_ode_func’ is for calling the saved function.
  • t_span is for time span.
  • For saving the image for each point of pendulum ‘saveas’ command is provided.
  • If matlab is used then the ‘getframe’ command is provided to make the movie file.

ERROR:

1. t_span

2. error in the plot

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.