Project

simple pendulum animation

Youtube link for the video:

https://youtu.be/nSOCvfvs5Ec

Plot of displacement vs time:

Above is the plot of displacement of simple pendulum with respect to time. As according to initial condition at t=0sec, the displacement is also at 0. But the displacement is not decaying to zero with respect to given time of 0-20sec, this is because of the low damping. If the damping value increased then the displacement comes to zero.

Plot of angular velocity vs time:

Again the graph agrees with the initial condition of at t=0sec, angular velocity is 3rad/sec.

MATLAB Code:


%let theeta=y
clear all
close all
clc
m=1;
b=0.05;
L=1;
g=9.81;
r=g/L;
k=b/(m*L);
f=@(t,y) [y(2);-k*y(2)-r*sin(y(1))];
t=[0 20];
y0=[0 3];
[t,y]=ode45(f,t,y0); %solving of ode

O=[0 0];
axis(gca,\'equal\');
axis([-1.5 1.5 -1.5 1.5]);
grid on;

for i=1:length(t)
    P=L*[sin(y(i,1)) -cos(y(i,1))]
    O_circle=viscircles(O,0.01);
    pend=line([O(1) P(1)],[O(2) P(2)]);
    ball=viscircles(P,0.05);
    pause(0.001);
    movievector(i)=getframe(gcf);
    if i<length(t)
        delete(pend);
        delete(ball);
        delete(O_circle);
    end
end
%% saving the movie

mywriter=VideoWriter(\'simple_pendulum_animation\');
mywriter.FrameRate=20;
open(mywriter);
writeVideo(mywriter,movievector);
close(mywriter);

%% plotting displacment and angular velocity

figure(1)
plot(t,y(:,1))
xlabel(\'time\')
ylabel(\'displacement\')
figure(2)
plot(t,y(:,2))
xlabel(\'time\')
ylabel(\'angular velocity\')
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.