SIMULATION OF AN OSCILLATION OF A 2-D PENDULUM BY USING SECOND ORDER ORDINARY DIFFERENTIAL EQUATION

In this report, I have simulated the oscillation of 2D pendulum and also generate a plot of 'angular_displacement' & 'angular_velocity' vs "time" in octave.

Consider a pendulum which is having a string of length of '1metre' connected to a ball of mass,m=1kg such that it is having fixed support from another end.Now suppose, the  pendulum is at stationery position at initial stage.Now, when an external force is applied,by Newton's law of motion it get motion to oscillate.As such, the phenomena of oscillation of pendulum comes into play.

So in order to trace out the motion of pendulum .Here I have used the concept of physics which says the motion of pendulum can be derived through the second order of ordinary differential equation.The equation of pendulum oscillation is given by,

 

where, θ= angular displacement.

           b=damping coefficient.

           t=time(sec)

           m=mass(kg)

           g=gravity(9.8m/s^2)

           l=length of string (metre).

 

Now with the help of this equation, I have written down a code which help me in tracing the motion of pendulum and also help me in generating the code.

In the code below,I have assumed the intial condition as

 angular_displacement=0,     angular_velocity=3 rad/sec.

while other assumptions are:- time=0 to 20 second, mass=1 kg, length=1 metre

, damping coefficients=0.05.

clear all
close all
clc
t_span=linspace(0,20,200);
theta_0=[0 3];
[t result]=ode45('pendulam_oscillation',t_span,theta_0);
figure(1)
plot(t,result(:,1),'r')
hold on
plot(t,result(:,2),'b')
xlabel('time(s)')
ylabel('amplitude')
legend('angle(rad)','angular velocity(rad/sec)')
 
  ct=1;
  x0=0; 
  y0=0;

 figure(2)
 for i=1:length(t)
   clf()
  y(i)=-cos(result(i,1));
  x(i)=sin(result(i,1));
  plot([x0,x(i)],[y0 y(i)],'linewidth',5,'color','b')
  axis([-1.5 1.5 -1.5 1])
  hold on
  plot(x(i),y(i),'marker','o','markersize',20,'markerfacecolor','r')
  hold on
  plot([-1 1],[0 0],'linewidth',5,'color','g')
  grid on 
  pause(0.001);
  text=sprintf("pendulum%d.png",ct);
  saveas(2,text)
  pause(0.001);
  ct=ct+1;
  end

 

In the code above, I have called the function named as "pendulum_oscillation". The function is defined as:-

function [thetadot]= pendulam_oscillation(t,theta);
 b=0.05;
 m=1;
 l=1;
 g=9.81;
 r=(g/l);
 k=(b/m*l);
  thetadot=zeros(2,1);
  thetadot=[theta(2);-r*sin(theta(1))-k*theta(2)];
 end
 

In this above function, the second order differential equation has been solved by using the concept of "state variable". In this concept, we basically defined a matrix according to our requirement. for eg,

Let,

x=[x1   x2].

S=[x1  x2.]

here  number of dot(.) as a suffix defines the order of derivative.Similarly

S.=[x1. x2..], here S.  derivates whole terms in a matrix to next higher derivative.

here in octave/matlab  instead of defining terms, we directly use matrix terms as a state variable which implicitly takes derivative of terms and later on terms are defined by us which is then solved by the octave for higher order terms.And thats how this concept works,

like,  [ dθ1/dt   dθ2/dt]=[theta(2)  -r*sin(theta(1))-k*theta(2)]

here,  theta(1) is nothing but "θ" which is derived implicitly by octave/matlab .

After that running the code successfully, I have generated the plot.

 

 

 


Projects by Shyam Rai

THEORY:- BOUNDARY CONDITION :- IN PHYSICS ,THESE ARE THOSE CONDITIONS WHICH ARE APPLIED AT THE BOUNDARY OF THE DOMAIN . IT SPECIFIES THE CONDITION AT BOUNDARY ON THE BASIS OF WHAT THE GOVERNING EQUATION DEFINES THE CONDITION OF DOMAIN ALONG WITH THE HELP OF INTIAL COND Read more

OBJECTIVE:- STEADY STATE SIMULATION OF FLOW OVER A THROTTLE BODY . SOFTWARE USED :- 1. CONVERGE STUDIO:- TO SETUP THE MODEL.  2. CYGWIN:- FOR RUNNING THE SIMULATION. 3. OPENFOAM:- TO VISUALIZE THE DIFFERENT POST-PROCESSED RESULT.   THEORY:- HERE, WE HAV Read more

OBJECTIVE:- STEADY STATE SIMULATION OF FLOW OVER A THROTTLE BODY . SOFTWARE USED :- 1. CONVERGE STUDIO:- TO SETUP THE MODEL.  2. CYGWIN:- FOR RUNNING THE SIMULATION. 3. OPENFOAM:- TO VISUALIZE THE DIFFERENT POST-PROCESSED RESULT.   THEORY:- HERE, WE HAV Read more

AIM:- IN THIS PROJECT SIMULATION IS DONE ON THE FLUID FLOW THROUGH PIPE USING OPENFOAM SOFTWARE AND MATLAB . THE TOPIC GIVEN BELOW IS COVERED IN THIS                      PROJECT. TO MAKE A PROGRAM IN MATLAB THAT Read more

AIM:- IN THIS PROJECT SIMULATION IS DONE ON THE FLUID FLOW THROUGH PIPE USING OPENFOAM SOFTWARE AND MATLAB . THE TOPIC GIVEN BELOW IS COVERED IN THIS PROJECT. TO MAKE A PROGRAM IN MATLAB THAT CAN GENERATE MESH AUTOMATICALLY FOR ANY WEDGE ANGLE AND GRADING SCHEME. TO Read more

AIM :- IN THIS PROJECT, I HAVE WORKED ON SIMULATING THE FLOW OF FLUID THROUGH  THE DOMAIN (CONTROL VOLUME). DESCRIPTION:- THE DOMAIN IS NOTHING ELSE, IT IS JUST A CONTROL VOLUME THROUGH WHICH I HAVE SIMULATED THE RESULT OBTAINED FROM THE GOVERNING EQUATION. THE Read more

  IN THIS PROJECT, I HAVE WORKED ON THE ONE DIMENSIONAL SUPERSONIC NOZZLE FLOW. IN THIS FLOW, I HAVE ASSUMED THE FLOW TO BE STEADY,ISENTROPIC. IN THIS NOZZLE, I HAVE CONSIDERED THE FLOW AT INLET SECTION COMES FROM RESERVOIR WHERE THE PRESSURE, TEMPERATURE ARE DENO Read more

  In this project, I have worked on the simulation of conduction of temperature heat in two dimensional space (2D domain).  The aim was to determine the rate of flow of  heat due to temperature difference over the space domain under steady condition and Read more

In this programming, I have derived the four order approximation of second order derivative using finite difference method. In Finite difference method,we generally convert ordinary differential equation into difference equation. In order to achieve so, we use simple t Read more


Loading...

The End