Pendulum by Dereddy Santhosh
Run The code and wait untill the animation stops and the graph will appear(if you close the animation window in the middle it will cause disturbance to the program).
I have tried to create the movie out of the animation but some error is popping up saying permission is denied. So I have recorded the video using the phone camera and uploaded it to the youtube.
https://youtu.be/KlLRGTeGpG4
clear all
close all
clc
%given data
g = 9.8;% gravity in m/sec^2
l= 1; %length of the pendulam
m=1; %mass of the ball in kg
b=0.05; %damping co-efficient
%simplifying
k=b/m;
r=g/l;
% simple pendulum ode
f= @(t,x) [x(2);-k*x(2)-r*sin(x(1))];
%initial conditions
y=[0; 3];
%solving the ode. The time interval starts from 0 to 20 seconds
[t,x]=ode45(f,[0 20],y);
% creating the animation of the pendulam
o=[0 0];
axis(gca,\'equal\');
axis([-1.5 1.5 -1.5 0.2]);
grid on;
%loop for animation
for j=1:length(t);
%mass point
p=[sin(x(j,1)), -cos(x(j,1))];
%circle origin
origin_circle= viscircles(o,0.01);
%pendulum
Pendulum= line([o(1) p(1)], [o(2) p(2)]);
%Ball
ball=viscircles(p,0.05);
%Time interval to update the plot
pause(0.0001);
%delete the previous object if it is not the final loop
if j<length(t);
delete(Pendulum);
delete(ball);
delete(origin_circle);
end
end
%plotting the graph
plot(t,x(:,1));
hold on;
plot(t,x(:,2));
xlabel(\'time(sec)\');
ylabel(\'amplitude\');
legend(\'angle\',\'angular speed\');
This is the graph that laid between the two plots and the time is (0-20) seconds. position is 0 and initial velocity is 3 rad/sec^2 which is 3m/s2 since lenght of pendulum is 1 meter.
plot(1) :- it is the graph between the time and the angular displacement or angle of the pendulum.
Plot(2) :- This graph is between the time and angular speed.