clear all;
clc
close all;
% inputs
b=0.05;
g=9.81;
l=1;
m=1;
theta_0=[0;3];
t_span=linspace(0,20,300);
[t,results]=ode45(@(t,theta_0) [theta_0(2);(-b/m)*theta_0(2)-(g/l)*sin(theta_0(1))],t_span,theta_0);
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
legend('angular_displacement','angular_velocity')
figure(2)
ct=1;
for i =1:length(t_span)
x0=0;
y0=0;
x1=l*sind(results(i,1));
y1=-l*cosd(results(i,2));
plot([x0,x1],[y0,y1],[1 -1],[0,0],'linewidth',5)
hold on
plot(x1,y1,'v','MarkerSize',30,'MarkerFaceColor','#EDB120')
axis([-1 1 -1 1])
grid on
pause(0.2)
M(ct)=getframe(gcf); % collects all the figures in single window
ct=ct+1;
end
movie(M)
videofile=VideoWriter('simple_pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)