STUDY OF PENDULUM MOTION USING ORDINARY DIFFERENTIAL EQUATION
STUDY OF PENDULUM MOTION USING ODE EQUATION:
ODE means ordinary differential equation.Ordinary differential equation is a differential equation containing one or more functions of one independent variable and its derivatives.
APPLICATIONS OF ODE :
ODE is used in the study of
- Mechanics of particles.
- Fluid mechanics .
- Mechanics of deformable solids.
- Statistical mechanics.
It plays a vital role in
- Radioactive decay.
- Newton's Law of cooling.
- Population dynamics.
In this case we are going to use ODE to study the behaviour of pendulum motion.
PARAMETERS REQUIRED:
- l,length of the arm=1 metre.
- m,mass of the bob(ball)=1kg.
- b,damping factor=0.05.
- g,acceleration due to gravity=9.81m/s^2.
ORDINARY DIFFERENTIAL EQUATION:
`(D^2theta)/(Dt^2)+(b/m)*(Dtheta)/(Dt)+(g/l)*sintheta=0`
CODE EXPLANATION:
ODE consists of first order and second order derivatives of theta (angular displacement). First the value of theta is assigned to another variable(theta 1).Then the first order derivative of theta is assigned to another variable(theta 2). And now the derivative of theta2 is the second order derivative of theta 1.And then ODE is formed accorgingly and it is saved as a function . Then a initial values of angular velocity and displacement are assigned to a variable theta_0. The ode result for corresponding time values are obtained using the ode45 command and ode function and plotted. Then the pendulum bob is generated using the Marker command.It is then placed such that it is connected to the arm.The position of the pendulum is screenshoted and converted to a video.
CODE AND ANIMATION:
https://drive.google.com/file/d/1l5Y9lUAln6vdTRtWrH2G1mn_KIoiYJKg/view
FUNCTION:
function[dtheta_dt]=ode(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
CODE:
clear all;
close all;
clc;
b=0.05;
g=9.81;
l=1;
m=1;
theta_o=[0;3];
t_span=linspace(0,20,300);
[t,results]=ode45(@(t,theta)ode(t,theta,b,g,l,m),t_span,theta_o);
subplot(5,4,[13,14,17,18]);
plot(t,results(:,1),'color','b');
hold on;
plot(t,results(:,2),'color','r');
hold off;
subplot(5,4,[15,16,19,20]);
plot(results(:,1),results(:,2));
xlabel('Position')
ylabel('angular_velocity');
c=1;
for i=1:length(results(:,1));
x0=0;
y0=0;
x1=l*sin(results(i,1));
y1=-(l*cos(results(i,1)));
subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12]);
plot([-1 1],[0 0],'linewidth',4,'color','k');
hold on;;
plot([x0 x1],[y0 y1],'linewidth',2,'color','r');
hold on;
%r=0.075;
%cir_deg=linspace(0,2*pi,1000);
%xc=r*cos(cir_deg);
%yc=r*sin(cir_deg);
%plot(x1+xc,-(y1+yc),'linewidth','2');
%hold off;
plot (x1,y1,'-o','markers',20,'markerfacecolor','b');
%r=0.25;
%rectangle('position',[(x1-(r/2)),(y1-(r/2)),(r,r),'curvature',[1,1],'facecolor','r','linewidth',3];
%hold on;
%axis equal
grid on;
axis([-1.5 1.5 -1.5 1]);
pause(0.0003);
hold off;
M1(c)=getframe(gcf);
text=sprintf('text%d.png',c);
saveas(gca,text);
c=c+1;
end
%movie(M1)
%videofile=videowriter('pendulum.avi''uncompressed avi');
%open(videofile);
%writevideo(videofile,M1);
%close(videofile);