PENDULUM MOTION
WHAT ARE ODE( Ordinary Differential Equation)?
In mathematics, an ordinary differential equation (ODE) is a differential equation containing one or more functions of one independent variable and the derivatives of those functions. The term ordinary is used in contrast with the term partial differential equation which may be with respect to more than one independent variable.
n Engineering, ODE is used to describe the transient behaviour of a system. A simple example is a pendulum. The way the pendulum moves depends on the Newtons second law. When this law is written down, we get a second order Ordinary Differential Equation that describes the position of the "ball" w.r.t time.
So, the ODE for pendulum motion is given as,
`(d^2theta)/(dt^2)+b/m.(d theta)/dt+g/Lsintheta=0`
to solve the ODe we substitute, `theta=theta1` which is displacement
differentiate the above, we get
`(d theta)/dt=(d theta1)/dt` i.e. change in displacement
Since, change in displacement is Velocity.
Therefore, `(d theta1)/dt= theta2` i.e.`theta2= Velocity`
Now if we differentiate the `theta2`, we get `(d theta2)/dt`
also, `(d theta2)/dt= (d^2theta1)/dt` from change in velocity equation.
Now, substituting in the main ODE equation
`(d theta2)/dt+b/m theta2+g/Lsin theta1=0`
`(d theta2)/dt= (-b/m theta2 )- g/L sin theta1`
Following is the plot for the velocity and displacement of the Pendulum. The negative and positive signs show the swinging motion to left and right respectively. As the simulation proceeds the oscillation of the wave goes on decreasing which is due to the slowdown in the motion of the pendulum. Also as defined in the initial condition, it can be seen that the Angular Velocity is 3 m/s2 and the displacement is 0 metres.
Following is the Matlab Code for the Pendulum Motion.
clear all
close all
clc
%Solving the ODE for damped pendulum
% length of the pendulum arm in metre
L= 1;
%mass of the ball in kg
m=1;
%damping coefficient
b=0.05;
%gravity in metre/second^2
g=9.81;
%Initial condition
theta_0= [0 3];
%Simulation time
t_span= linspace(0,20,100);
%Solving the ODE with function
[t, results]= ode45('pendulum_damped_ode',t_span,theta_0);
%Plotting
figure(1)
plot(t,results(:,1));
hold on
plot(t,results(:,2));
legend('Displacement','Angular Velocity');
xlabel('Time');
ylabel('Plot');
grid on
saveas(gca,'pendulum Figure(1).jpg');
%Animation of the pendulum
ct=1;
results_disp= (results(:,1));
for i=1:length(results_disp)
%Initial coordinates of X,Y of pendulum
x0=0;
y0=0;
%Moving coordinates of pendulum
x1= L*sin(results_disp(i));
y1=-L*cos(results_disp(i));
%Plotting of the pendulum
figure(2)
plot([-1 1],[0 0],'b','linewidth',4);
hold on
plot([x0,x1],[y0,y1],'g','linewidth',2);
plot(x1,y1,'O','MarkerFaceColor','red','MarkerEdgeColor','red');
grid on
axis([-1.5 1.5 -1.5 1]);
pause(0.01)
%Stiching all the frames in M array to create animation
M(ct)=getframe(gcf);
hold off
%Lap counter
ct=ct+1;
end
movie(M)
videofile=VideoWriter('Pendulum_Motion.avi','uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
The function used for solving the ODE is given below,
function ydot = pendulum_damped_ode(t,theta)
% length of the pendulum arm in metre
L= 1;
%mass of the ball in kg
m=1;
%damping coefficient
b=0.05;
%gravity in metre/second^2
g=9.81;
k = b./m;
r = g./L;
theta1 = theta(2);
theta2 = -k*theta1 - r*sin(theta(1));
ydot = [theta1 ; theta2];
end
ANIMATION OF THE PENDULUM: