Click here for Animation
function [dtheta_dt] = ode_func(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
clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 1;
theta_0 = [0 ; 3];
t_span = linspace(0,20,500);
%solving ODE
[t, results]= ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
%plotting
ct = 1;
for i = 1:500
plot([0 -sin(results(i,1))] , [0 -cos(results(i,1))],\'O\');
line([0 -sin(results(i,1))] , [0 -cos(results(i,1))],\'linewidth\',2);
axis([-1 1 -1.2 0]);
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
end
movie(M);
videofile = VideoWriter(\'xyz.AVI\',\'Uncompressed AVI\');
open(videofile);
writeVideo(videofile,M);
close(videofile);