SOLVING THE MOTION OF SIMPLE PENDULUM IN MATLAB
AIM:
To write a matlab program to simulate the simple harmonic motion of simple pendulum by solving the ODE that govern the motion of the simple pendulum.
The ODE that describes the motion is :
`(d^(2 ) θ)/(dt^2 )+(b/m)(dθ/dt)+(g/l) sinθ=0`
In the above equation,
g=acceleration due to gravity
L=length of the pendulum
m=mass
b=damping coefficient
θ=angular displacement
where
g=9.81 m/s2
m=1 kg
b=0.05
The time span taken is 0 to 20 seconds.The average angular velocity is 3 rad/sec.
PROCEDURE:
In the above equation let us consider that
θ=θ1
dθ/dt=θ2.
Therefore the equation becomes
dθ2/dt=-(b/m)(θ2)-(g/l)sin θ1
MATLAB PROGRAM:
The previous two equations are solved in matlab.
The ODE function is:
function [d1]=odefun_pendulum(t,d,b,l,m,g);
d1=zeros(2,1);
d1(1)=d(2);
d1(2)=((-g/l)*sin(d(1)))-((b/m)*d(2));
end
In the function instead θ, variable d is used.
The main program is as follows:
clear all
close all
clc
t=[0 20];
d0=[0 3];
b=0.05;
l=1;
m=1;
g=9.81;
[t,d]=ode45(@(t,d)odefun_pendulum(t,d,b,l,m,g),t,d0);
figure(1)
plot(t,d(:,1),'color','r','linewidth',3)
hold on
plot(t,d(:,2),'color','b','linewidth',3)
xlabel('Time')
legend('angular dispalcement','angular velocity')
ct=1;
for i=1:length(d(:,1))
x0=0;
y0=0;
x1=l*sin(d(i,1));
y1=-l*cos(d(i,1));
figure(2)
plot([x0 x1],[y0 y1],'linewidth',2,'color','b')
hold on
plot(x1,y1,'-o','markers',20,'markerfacecolor','r')
grid on
axis([-1.5 1.5 -1.5 1.5])
pause(0.3);
hold off
q(ct)=getframe(gcf);
ct=ct+1;
end
movie(q)
videofile=VideoWriter('pendulam_damped.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,q)
close(videofile)
Inbuilt matlab function ode45 is used to solve the Ordinary Differential equation governing the motion
The results we got after plotting the graph of angular displacement and angular velocity w.r.t time is:
In the above plot it is seen that the amplitudes of the angular displacement and angular velocity decreases with increase in time. This is maily due to the presence of the damping factor.
ANIMATION OF THE MOTION OF PENDULUM:
In the figure 2, the animation is being created.
The origin is at the pivot points,
x0=0
y0=0.
x1 and y1 depict the position of the bob.
The video is being uploaded on the youtube platform.