Project

SIMPLE PENDULUM MOTION

PROJECT: TRANSIENT BEHAVIOUR OF SIMPLE PENDULUM.

AIM: To make a transient behavior of simple pendulum using matlab and animate the motion of the pendulum.

GOVERNING EQUATONS:

`(d^2 θ)/(dt^2 )+b/m dθ/dt+g/l sin⁡θ`

Breaking down the above second order differential equation to first order differential equation.

`θ=θ1`

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

`(d^2 θ)/(dt^2 )=(d^2 θ1)/(dt^2 )=d^2 theta2//dt`

`(d theta2)/dt=-b/m theta2-g/l sintheta`

below is the pictorial representation of simple pendulum with forces acting on it.

--> EXPLANATON OF CODE

1) Firstly the required inputs are given (length,gravity,mass,damping coeff)

2) then function is created for the governing equation.

3) then after the function is called in the ode45 solver

4)ploting the dispalcement and angular velocity with respect to the time.

5) plot for the animation and creating the movie for the motion of the pendulum.

CODE:

MAIN CODE:

clear all
close all
clc

b=0.02;    %damping coefficient
g=9.81;    %gravity
l=1;       %length of the pendulum
m=0.1;      %mass of the ball
 
theta_0=[0;5];    %intial conditon of angular displacement and velocity

t_span=linspace(0,10,500);  % time duration
 %ode solver for (t ,theta)
[t,results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m), t_span , theta_0);
 %plotting of displacement and angular velocity with respect to time
subplot(2,1,1)
plot(t,results(:,1))
ylabel('displacement')
xlabel('time')
hold on
subplot(2,1,2)
plot(t,results(:,2))
ylabel('velocity')
xlabel('time')

%simulation of pendulum
ct=1;       %intializing count=1.
theta_1=results(:,1);
for i=1:length(results(:,1))
     %intial cordinates
     x0=0;
     y0=0;
     theta_2=theta_1(i);
     %final cordinates
     x1=1*sin(results(i,1));
     y1=-1*cos(results(i,1));
    
%ploting for animation.
    plot([-0.5,0.5],[0,0],'linewidth',3,'color','r');  %base of pendulum
    line([x0 x1],[y0 y1],'linewidth',2,'color','g');  %string of  pendulum
    hold on;
    
    plot(x1,y1,'o','markers',20,'markerfacecolor','b'); %bob of pendulum
    grid on;
    axis([-1.5 1.5 -1.5 0.5]);   %limits for axis
    pause(0.01);     
    hold off;
    M(ct)=getframe(gcf);
    ct=ct+1;        %increasing count value.
end
  

%creating movie
movie(M);
videofile = VideoWriter('pendulum_anm.avi','uncommpressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);

FUNCTION CODE:

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

ERRORS:

one argument theta_0 was missing which was later corrected.

YOUTUBE LINK :https://youtu.be/dP9sDGHp6Ak

Results:

result for displacement and velocity.

all varaibles:

CONCLUSION: Transient bhevaiour of the simple pendulum is studied and animaton of the motion is done.

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.