clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 1;
%initial condition
theta_0 = [0;5];
% '0' is the initial displacement
% '0' is the initial velocity
%time points
t_span = linspace(0,10,500);
%solve ODE
[t, results] = ode45(@(t,theta)ode_func(t, theta, b, g, l, m), t_span, theta_0);
figure(1)
plot(t,results (:,1))
hold on
plot(t,results (:,2))
xlabel('time')
ylabel('plot')
legend('t', 'results')
%Creating animatiom
ct=1;
for i=1:length(t);
x=-1*sin(results(i,1));
y=-1*cos(results(i,1));
figure(2)
plot(0,0,'o','Markersize',10,'color','b','Markerfacecolor','b') %allocting co-ordinates for fixed support
plot([0 x],[0 y],'linewidth',2,'color','b') %allocting co-ordinates for pendulum string
hold on
plot(x,y,'-o','markers',10,'markerfacecolor','r') %allocting co-ordinates for BOB
xlim([-3 3]); % for setting the limits of x-axis
ylim([-1.5 0]); % for setting the limits of y-axis
grid on
pause(0.002);
hold off
M(ct)=getframe(gcf);
ct=ct+1;
end
movie(M)
videofile = Videowriter('second_order_differential.avi', 'uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)