Persamaan gerak peluru
Simulasi gerak peluru :
Program simulasi gerak peluru dengan matlab :
% Program gerak projectile
% Andri Sofyan Husein
clear all
clc
h = figure(1);
set(h,'Position',[100 100 500 280]);
set(gcf,'Color',[1 1 1])
V0 = 3; % kecepatan awal projectile (mtere/second)
g = 9.8; % konstanta percepatan gravitasi (meter/second^2)
theta_1 = 30*pi/180; % sudut projectile 1
theta_2 = 45*pi/180; % sudut projectile 2
theta_3 = 65*pi/180; % sudut projectile 3
x0 = 0.5; % Posisi horizontal mula-mula (meter)
y0 = 0; % Posisi vertikal mula-mula (meter)
t_end_1 = 2*V0*sin(theta_1)/(g);
t_end_2 = 2*V0*sin(theta_2)/(g);
t_end_3 = 2*V0*sin(theta_3)/(g);
dt = t_end_3/200;
t1 = 0:dt:t_end_3;
x_k1 = x0+V0.*t1.*cos(theta_1);
y_k1 = y0+V0.*t1.*sin(theta_1)-0.5.*g.*t1.^2;
x_k2 = x0+V0.*t1.*cos(theta_2);
y_k2 = y0+V0.*t1.*sin(theta_2)-0.5.*g.*t1.^2;
x_k3 = x0+V0.*t1.*cos(theta_3);
y_k3 = y0+V0.*t1.*sin(theta_3)-0.5.*g.*t1.^2;
Horizontal = x0+V0*t_end_3*cos(theta_3);
Vertikal = y0+V0^2*sin(theta_2)^2/(2*g);
figure(1)
plot(x_k1,y_k1,'r-.','LineWidth',1)
axis([0.8*x0 1.3*Horizontal 0 1.8*Vertikal])
title('Mekanika Klasik: Projectile')
hold on
plot(x_k2,y_k2,'b-.','LineWidth',1)
plot(x_k3,y_k3,'k-.','LineWidth',1)
legend('\theta = 30^o','\theta = 45^o','\theta = 65^o')
text(x0-.05,1.5*Vertikal,sprintf('V0 = 3 m/s'),'fontsize',10);
xlabel('x(meter)')
ylabel('y(meter)')
set(gca,'fontsize',10)
head1=line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',30);
head2=line(x0,y0,'color','b','linestyle','.','erasemode','xor','markersize',30);
head3=line(x0,y0,'color','k','linestyle','.','erasemode','xor','markersize',30);
t = 0;
poto = 0;
while t<t_end_3
poto = poto+1;
t = t+dt;
x1 = x0+V0.*t.*cos(theta_1);
y1 = y0+V0.*t.*sin(theta_1)-0.5.*g.*t.^2;
x2 = x0+V0.*t.*cos(theta_2);
y2 = y0+V0.*t.*sin(theta_2)-0.5.*g.*t.^2;
x3 = x0+V0.*t.*cos(theta_3);
y3 = y0+V0.*t.*sin(theta_3)-0.5.*g.*t.^2;
set(head1,'xdata',x1,'ydata',y1);
set(head2,'xdata',x2,'ydata',y2);
set(head3,'xdata',x3,'ydata',y3);
M(poto)=getframe(h);
drawnow;
% saveas(gcf, ['fig' ,num2str(poto),'.png']);
end
movie2avi(M,'Projectile.avi', 'compression', 'none');