To Simulate The Transient Behavior Of A Simple Pendulum And obtain An Animation Of The Same
OBJECTIVE:-
To Simulate The Transient Behavior Of A Simple Pendulum And obtain An Animation Of The Same.
WHAT IS 2ND ORDINARY DIFFIRENTIAL EQUATION:-
An ordinary differential equation (ODE) is a differential equation containing one or more functions of one independent variable and the derivatives of those functions.
INTRODUCTION:-
A pendulum is a weight suspended from a pivot so that it can swing freely. When a pendulum is displaced sideways from its resting, equilibrium position, it is subjected 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 oscilate about the equilibrium position and swinging back and forth.
The time for one complete cycle, a left swing and a right swing, is called the period. The period depends on the length of the pendulum and also to a slight degree on the amplitude, the width of the pendulum\'s swing.
PERIOD OF OSCILLATION:-
The period of swing of a simple gravity pendulum depends on its length, the local strength of gravity, and to a small extent on the maximum angle that the pendulum swings away from vertical, θ, called the amplitude. It is independent of the mass of the bob. If the amplitude is limited to small swings.
Time period is the time taken by the bob of the simple pendulum to make one complete oscillation. It is represented by the letter T.
An ideal simple pendulum consist of a small diameter bob and a string that has a very small mass but is stron enough no to stretch appreciably. The linear displacement from equilibrium is S, the length of the arc. Force acting on the bob are shown below figure.
A net force of -mg sinθ
Towards the equilibrium position-that is a restoring force.
Figure:- Force Acting On A Simple Pendulum
The distance between the point of suspension of the pendulum and its Centre of Gravity (C.G.), which is the C.G. of the bob, is called the length of the simple pendulum. It is represented using the alphabet ( L).
EQUATION:-
The behaviour of a simple pendulum can be transform into an equivalent spring, mass, damper system, which behaves on the basis of the following diffirential equation:-
Where....
m = 1 (kg) = mass of the pendulum bob,
b = 0.05 = damping coefficient,
g = 9.81 (m/s^2) = gravity,
θ = angular displacement of the pendulum,
L = 1 (m) = length of the pendulum
Simulate the motion between 0-20sec, for angular displacement = 0, angular velocity = 3 rad/sec at time t = 0
%Write a program to simulate the transient behaviour of a simple pendulum and to create an animation of it\'s motion.
% Step 1
% clearing previous workspace, command window & closing all plot
clear all
close all
clc
% Step 2
% Defining given inputs in problem statement
b=0.05;
g=9.81;
L=1;
m=1;
% Step 3
% Defining initial conditions of angular displacement and velocity
theta_0=[0;3];
% Step 4
%Defining time interval with linspace command
t_span=linspace(0,10,500);
% Step 5
% solve ODE & calling the function ode_func
[t, results]=ode45(@(t,theta) ode_func(t,theta,b,g,L,m),t_span,theta_0);
% Step 6
% Plotting the first Graph which show variation of ang. Displacement & % velocity with time
figure(1)
hold on
plot(t,results(:,1),\'color\',\'g\',\'linewidth\',3)
plot(t,results(:,2),\'color\',\'m\',\'linewidth\',3)
legend(\'Angular Displacement\',\'Angular Velocity\')
hold off
ylabel(\'Plot\')
xlabel(\'Time\')
title(\'ANGULAR DISPLACEMENT vs ANGULAR VELOCITY\')
% Step 7
% Plotting the second Plot to show animation of pendulum
figure(2)
% Step 8
% Defining array for angular displacement and angular velocity
displacement=results(:,1);
velocity=results(:,2);
ct=1;
% Step 9
% Defining for loop to create diffirence position of pendulum
for i=1:length(displacement)
% Step 10
% Calculate starting and ending position of pendulum rop
X0=0;
Y0=0;
X1=L*cos(displacement(i)-pi/2);
Y1=L*sin(displacement(i)-pi/2);
% Step 11
% Creating Support for pendulum
plot([-1 1],[0.075 0.075],\'linewidth\',15,\'color\',\'b\')
hold on
% Step 12
% Plotting pendulum rop using co-ordinate
plot([X0 X1],[Y0 Y1],\'linewidth\',4,\'color\',\'k\');
% Step 13
% Creating pendulum ball using markersize and markerfacecolor command
plot(X1,Y1,\'-O\',\'markersize\',35\',\'markerfacecolor\',\'r\',\'markeredgecolor\',\'k\')
plot(X0,Y0,\'-O\',\'markersize\',5\',\'markerfacecolor\',\'b\')
axis([-1.5 1.5 -1.5 1]);
% Step 14
% Writing corresponding valve of angular disolacement and velocity
dis=displacement(i);
vel=velocity(i);
txt1=[\'Angular Displacement: \' num2str(dis) \' rad\'];
text(-0.5,0.75,txt1,\'color\',\'r\');
txt2=[\'Angular Velocity: \' num2str(vel) \' rad/s\'];
text(-0.5,0.5,txt2,\'color\',\'b\');
pause(0.03);
% Step 15
% Defining initials for creating animation
M(ct)=getframe(gcf);
ct=ct+1;
hold off
end
% Step 16
% Progrma for creating animations
movie(M)
videofile=VideoWriter(\'Pendulum.avi\',\'Uncompressed AVI\');
open(videofile);
writeVideo(videofile,M);
close(videofile);
FUNCTION:-
% Step 17
% Creating Function for calculation of angular displacement and velocity
function[dtheta_dt]=ode_func(t,theta,b,g,L,m)
theta1=theta(1);
theta2=theta(2);
dtheta1_dt=theta2;
dtheta_dt=-(b/m)*theta2-(g/L)*sin(theta1);
dtheta_dt=[dtheta_dt;dtheta2_dt];
end
ERROR & SOLUTION:-
I did mistake during writing program in above image in red circle and hence it is small problem after that i did correct. num2str(dis)
OUTPUT:-
YOUTUBE ANIMATION LINK:-
%%% END OF THE REPORT %%%