Code covered by the BSD License

# Projectile Motion in Weak Gravitational Field,(g=3.71 m/s²)

### Youssef Khmou (view profile)

Simulation of triple projectile in weak gravitational field (Mars ).

Projectile_motion.m
% triple projectiles on Mars planet
% Simulating projectiles with different gravitational constant, the
% following assuptions are made :
% -zero air friction .
% -Initial position is on (0,0) for all the particles.
% (c) KHMOU Youssef,  Applied Physics 2013 .

close all;clear,
M=6.4185e+23;  % Mass in Kg
G=6.67384e-11; % Gravitational constant in m^3.kg^-1.s^-2
g=G*M/r^2;
% Initial conditions
theta=[15 23 34].*pi/180;
v0=[40.5 50.6 60.32];
Fs=8; % sampling frequency
% Time simulaion
t=0:1/Fs:100; % 100 seconds
x=[v0(1)*cos(theta(1)).*t;v0(2)*cos(theta(2)).*t;v0(3)*cos(theta(3)).*t];
y=[v0(1)*sin(theta(1)).*t-(0.5*g*(t.^2));v0(2)*sin(theta(2)).*t-(0.5*g*(t.^2));...
v0(3)*sin(theta(3)).*t-(0.5*g*(t.^2))];
y(y<0)=NaN;
xrange=[v0(1)^2/g*sin(2*theta(1));v0(2)^2/g*sin(2*theta(2));...
v0(3)^2/g*sin(2*theta(3))];
ymax=[(sin(theta(1))^2)*(v0(1)^2)/(2*g);(sin(theta(2))^2)*(v0(2)^2)/(2*g);...
(sin(theta(3))^2)*(v0(3)^2)/(2*g)];
hFig1=figure(1);
whitebg([0.25 0.25 0.25]);
AXES=[0 max(xrange) 0 max(ymax)];
xlabel('Ground distance (m)');
ylabel(' Height in (m)');
Title=strcat('Projectile Motion with g=',num2str(g),'m/s');
title(Title);
hold on;
n=1;
while (~isnan(y(1,n)) || ~isnan(y(2,n)) || ~isnan(y(3,n)))
plot(x(1,n),y(1,n),'>r',x(2,n),y(2,n),'>y',...
x(3,n),y(3,n),'>b','MarkerSize',2);
axis(AXES);
pause(0.03);
n=n+1;
end
L1=strcat('V_{01}=',num2str(v0(1)),'m/s',',\theta_{1}=',num2str(theta(1)*180/pi),'');
L2=strcat('V_{02}=',num2str(v0(2)),'m/s',',\theta_{2}=',num2str(theta(2)*180/pi),'');
L3=strcat('V_{03}=',num2str(v0(3)),'m/s',',\theta_{3}=',num2str(theta(3)*180/pi),'');
legend(L1,L2,L3);
hold off;