% main body
close all
clear all
clc
t = [0 20]
yo = [0 3]
[t, y] = ode45(\'ode_pendulum\',t,yo)
subplot(5,4,[13,14,15,16]);
plot(t,y(:,1),\'color\',\'r\');
hold on;
plot(t,y(:,2),\'color\',\'b\');
hold off;
subplot(5,4,[17,18,19,20]);
plot(y(:,1),y(:,2));
xlabel(\'position_Radians\')
ylabel(\'Angular_velocity\');
ct=1;
for i=1:length(y(:,1))
x0=0;
y0=0;
x1=1*sin(y(i,1));
y1=-1*cos(y(i,1));
subplot(5,4,[1,2,3,4,5,6,7,8,9,10,11,12]);
plot([-1 1],[0 0],\'linewidth\',4,\'color\',\'k\');
hold on
line([x0 x1],[y0,y1],\'linewidth\',2,\'color\',\'b\');
hold on;
plot(x1,y1,\'-o\',\'markers\',20,\'markerfacecolor\',\'r\');
grid on;
axis([-1.5 1.5 -1.5 1.5])
pause(0.03);
hold off
%q(ct)=getframe(gcf);
text=sprintf(\"pendulum%d.png\",ct);
saveas(1,text);
ct=ct+1;
end
% function
function [ydot] = ode_pendulum(t,y);
b = 0.05;
L = 1;
M = 1;
g = 9.81;
ydot = zeros(2,1);
ydot(1) = y(2)
ydot(2) = -((b/M)*y(2))-(g/L)*(sin(y(1)))
end