https://youtu.be/E7OrNK3sipw
% a program that will simulate the pendulum motion.
clear all;
close all;
clc;
b = 0.05;
g = 9.81;
m = 1;
l = 1;
%initial condition for displacement and velocity
%displacement is 0 and initial velocity is 3 m/s
theta_0 = [0;3];
%time points
t_span = linspace(0,20,500);
ct = 1;
%solve ODE
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
figure(1);
plot(results)
figure(2);
o =[0,0];
for i = 1:length(t)
x = l*sin(results(i,1));
y = -l*cos(results(i,1));
p = [x,y];
viscircles(p,0.05);
plot([-1 1],[0 0],[0,x],[0,y],'Marker','o','markersize',20,'linewidth',3);
axis([-1.5 1.5 -1.5 1]);
xlabel('x');
ylabel('y');
pause(0.03)
M(ct) = getframe(gcf);
ct = i+1;
end
movie(M)
videofile= VideoWriter('pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)