SIMPLE PENDULUM TRANSIENT BEHAVIOUR SIMULATION AND ANIMATION OF ITS MOTION
SIMPLE PENDULUM TRANSIENT BEHAVIOUR SIMULATION AND ANIMATION OF ITS MOTION ORDINARY DIFFERENTIAL EQUATION :
In mathematics, an ordinary differential equation (ODE) is a differential equation containing one or more functions of one independent variable and its derivatives. The term ordinary is used in contrast with the term partial differential equation which may be with respect to more than one independent variable
.Among ordinary differential equations, linear differential equations play a prominent role for several reasons. Most elementary and special functions that are encountered in physicsand applied mathematics are solutions of linear differential equations (see Holonomic function). When physical phenomena are modeled with non-linear equations, they are generally approximated by linear differential equations for an easier solution. The few non-linear ODEs that can be solved explicitly are generally solved by transforming the equation into an equivalent linear ODE (see, for example Riccati equation).Some ODEs may be solved explicitly in terms of known functions and integrals. When it is not possible, one may often use the equation for computing the Taylor series of the solutions. For applied problems, one generally use numerical methods for ordinary differential equations for getting an approximation of the desired solution.
2nd ORDER ODE EQUATION
`(d^2theta)/dt^2+b/m(d(theta))/dt+(g/l)sintheta=0`
where g = gravity in m/s2
L = length of the pendulum in m
clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 1
ct = 1;
% initial condition
theta_0 = [0;3];
% time points
t_span = linspace(0,20,500);
%solve ODE
[t,results] = ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
% plot of theta and velocity with time
figure(1)
subplot(2,1,1)
plot(t,results(:,1)) %angular displacement
xlabel('time')
ylabel('angular displacement')
title('plot between theta and time')
hold on
subplot(2,1,2)
plot(t,results(:,2),'color','r') %angular velocity
xlabel('time')
ylabel('angular velocity')
title('plot between velocity and time')
%Animation of the pendulum motion
theta = results(:,1);
ct =1;
for i= 1:length(t)
THETA = theta(i)
x0 = 0;
y0 = 0;
%origin suspending point of the string
x1 = l*sin(THETA);
y1 = -l*cos(THETA);
%end-point of the string
figure(2)
plot([x0 x1],[y0 y1],'linewidth',3,'color','b') %string plot
hold on
plot(x1,y1,'marker','o','markersize',30,'color','g','MarkerFaceColor','r') %bob plot
plot(x0,y0,'-*','linewidth',2,'color','y');
title('motion of pendulum')
hold off
axis([-2 2 -2 0])
pause(0.003)
%saving frames
M1(ct)=getframe(gcf);
ct=ct+1;
end
movie(M1);
videofile = VideoWriter('pendulum_animation.avi','Uncompressed avi');
open(videofile)
writeVideo(videofile,M1)
close(videofile)
`m = mass of the ball in kg,
b=damping coefficient.
FUNCTION AND 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
PLOTS