https://youtu.be/N84FFotaak0
%the function which is defined for second order ODE
function [dtheta_dt] = odefunc(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
%Solving the second order ODE
%Assumption in solving this is that the rope have negligible weight
clear all
close all
clc
%the inputs
b=0.05; %damping Co-efficient
m=0.1; %mass of the ball hanging to the rope
g=9.81; %gravity
l=1.5; %length of the ropes
theta_0=[0;180].*pi/180; %degree in radians
t_span=linspace(0,20,500); %time taken
D=result(:,1);
V=result(:,2);
%to save the figure of the damping
figure(501)
plot(t,result(:,1),'color', 'r','linewidth',3);
hold on
plot(t,result(:,2),'color', 'b', 'linewidth',3);
saveas(gcf,'pendulum.png')%saving image in the disk
ct=1;
for i=1:length(result(:,1))
X0=0;
Y0=0;
X1=l*sin(result(i,1))
Y1=-l*cos(result(i,1);
plot([-1,1],[0,0],'linewidth',4,'color','r')
line([X0 X1],[Y0 Y1],'linewidth',4,'color','g')
hold on
plot(X1,Y1,'o','markers',10,'markerfacecolor','b')
axis([-2 2 -2 2])
pause(0.03)
hold off
M(ct)=getframe(gcf)
ct=ct+1;
end
movie(M)
videofile=VideoWriter('Damping.avi','uncompressed AVI')
open(videofile)
writerVideo(videofile,M)
close(videofile)