Escolar Documentos
Profissional Documentos
Cultura Documentos
close all
clc
% Pendulum Constants
b=0.05;
m=1;
L=1;
g=9.81;
[t,theta]=ode45(@(t,theta) odefun_second_order_pendulum(t,theta,b,m,L,g),
t,theta0);
% [t,theta]=ode45('odefun_second_order_pendulum', t,theta0);
spatial_x=-sin(theta(:,1)); %rotating the axes by 90 degrees
spatial_y=-cos(theta(:,1)); %rotating the axes by 90 degrees
% % figure(1)
% % subplot(2,2,1)
% % plot(t,theta(:,1),'color','k','linewidth',2)
% % xlabel('Time')
% % ylabel('Angular Displacement')
% %
% % subplot(2,2,3)
% % plot(t,theta(:,1),'color','r','linewidth',2)
% % xlabel('Time')
% % ylabel('Angular Velocity')
% %
% % subplot(2,2,[2,4])
% % plot(theta(:,1),theta(:,2),'color','k','linewidth',2)
% % xlabel('Angular Displacement')
% % ylabel('Angular Velocity')
for n=1:length(t)-1
subplot(2,3,1)
plot(t(1:length(t)-1),theta(1:length(t)-1,1),'color','k','linewidth',2)
xlabel('Time')
ylabel('Angular Displacement')
hold on;
plot(t(n,1),theta(n,1),'-o','markers',8,'markerfacecolor','r');
hold off;
%
%
subplot(2,3,4)
plot(t(1:length(t)-1),theta(1:length(t)-1,2),'color','r','linewidth',2)
xlabel('Time')
ylabel('Angular Velocity')
hold on;
plot(t(n,1),theta(n,2),'-o','markers',8,'markerfacecolor','k');
hold off;
subplot(2,3,[3,6]);
plot(theta(1:length(t)-1,1),theta(1:length(t)-1,2),'color','k','linewidth',2)
xlabel('Angular Displacement')
ylabel('Angular Velocity')
hold on;
plot(theta(n,1),theta(n,2),'-o','markers',8,'markerfacecolor','r');
hold off;
% figure(4)
subplot(2,3,[2,5]);
z1=-2*L;
z2=-2*L+0.05;
while z1<2*L-0.05
rectangle('Position',[z1 0.05 0.1 0.1]);
rectangle('Position',[z1 0.25 0.1 0.1]);
z1=z1+0.1;
end
while z2<2*L-0.05*2
rectangle('Position',[z2 0.15 0.1 0.1]);
rectangle('Position',[z2 0 0.1 0.05]);
z2=z2+0.1;
end
line([-2*L,2*L],[0 0],'color','k','linestyle','-','linewidth',2);
line([0,0],[-1.5*L 0.5*L],'color','k','linestyle','--','linewidth',2);
xlim([-2*L,2*L])
ylim([-2.5*L,0.5*L])
viscircles([0,0],0.05,'Edgecolor','r')
line([0,spatial_x(n,1)],
[0,spatial_y(n,1) ],'color','k','linestyle','-','linewidth',4);
hold on;
plot(spatial_x(n,1),spatial_y(n,1),'-o','markers',30,'markerfacecolor','m');
plot(xy_r(1,:), xy_r(2,:),'color','b','linestyle','-.','linewidth',1) ;
hold off;
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
end