Project

Simulating the transient behaviour of a simple pendulum and to create an animation of it's motion using MATLAB.

AIM: Simulating the transient behaviour of a simple pendulum and to create an animation of it's motion using MATLAB.

definition: A simple pendulum is a bob suspended from a pivot so that it can swing freely uder the influence of acceleration due to gravity.

Theory:

A simple pendulum consists of a mass m hanging from a string of length L and fixed at a pivot point P. When displaced to an initial angle and released, the pendulum will swing back and forth with periodic motion. usually simple pendulum is seen in old clocks it will swings with in certain intervels of time.

diagram:

Formulas used:

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

here we consider

`theta=theta1`

`d theta/dt=d (theta1)/dt=theta2`

`d^2theta/dt^2=d^2 (theta1)/dt^2=d/dt(d( theta1)/dt)=d (theta2)/dt`

then here

`d (theta1)/dt=theta2 ;d (theta2)/dt=-b/m(theta2)-g/lsintheta1`

Given parameters:

damping coefficient(b)=0.05

mass(m)=0.1kg

length(l)=1m

acceleration due to gravity=9.81m/s^2

Program:

% program for second order differential equations
clear all
close all
clc

%inputs
d_c=0.05;
 g=9.81;
 l=1;
 m=1;
 
 %initial conditions
 
 theta_0=[0;3];
 
 % time parameters
 
 t_span=linspace(0,10,250);
 
 %  solving ODE

 [t,results]=ode45(@(t,theta) ode_func(t,theta,d_c,g,l,m),t_span,theta_0);
 
hold on
 plot(t,results(:,1));
  
 plot(t,results(:,2));
 
 hold off
 ylabel('angular velocty''angular dispalcement')
 
 xlabel('time')
  
 ct=1;
 
 for i=1:length(results)
     
     x0=0;
     y0=0;
   hh=results(i,1);
    
    
      x1=l*sin(hh);
     
         y1=-l*cos(hh);
      figure(2)
         
   plot(x1,y1,'marker','.','markersize',50)
   hold on
  plot([x0 x1],[y0 y1],'color','g')
   
   plot([-1 1],[0 0]);
  
   axis([-1 1 -1 1]);
    hold off
    
    M(ct)=getframe(gcf);
    ct=ct+1;
    
 end
  movie(M)
 videofile=VideoWriter('ode_simple_pendulum.avi','uncompressed AVI');
 
 open(videofile);
 writeVideo(videofile,M);
 close(videofile)
 

Function program:

function [dtheta_dt]=ode_func(t,theta,d_c,g,l,m)


theta1=theta(1)
theta2=theta(2)


dtheta1_dt=theta2;
dtheta2_dt= -d_c/m*theta2-(g/l)*sin(theta1);


dtheta_dt=[dtheta1_dt;dtheta2_dt];
end

Explantion of code:

* Enter the given data such as damping coeff,mass,length,gravity.

*Now take initial conditions time and angular velocity after provide the time parameters.

* Then take function to slove the ODE ,then here ODE45 is the inbuilt to slove the parameters.

*plot the results hold off in x-axis we are taking the time and y-axis angular velocity ,angular displacement.

*for loop enters taking ct=1;ct=ct+1 to avoiding the overlap, after ploting the results and axis

* use the movie command to get the animat video.

Output graph:

Animation video:

RE$ULT:

The transient behaviour of a simple pendulum is simulated and to animation of it's motion is created using MATLAB.

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.