clear all
close all
clc
% inputs
b = 0.05;
g = 9.81;
l = 1;
m = 1;
% initial condition
theta_0 = [0;3];
% time points
t_span = linspace(0,20,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')
% aimation
ct = 1;
for i = 1 : length(results(:,1))
x0 = 0;
y0 = 0;
x1 = l*sin(results(i,1));
y1 = -l*cos(results(i,1));
figure(2)
plot([-1 1], [0 0], 'LineWidth', 5)
axis([-2 2 -2 2])
hold on
line([x0 x1], [y0 y1], 'Linewidth', 3)
plot(x1, y1, 'o', 'LineWidth', 20)
hold off
M(ct) = getframe(gcf);
ct = ct+1;
end
movie(M)
videofile = VideoWriter('Pendulum_Simulation.avi', 'Uncompressed AVI');
open(videofile);
writeVideo(videofile, M)
close(videofile)