%%Projectile motion 
%
%g acceleration due to gravity (m/s^2)
%v0 initial speed (m/s)
%a angle of inclination (rad)
%r number of timesteps
%The ball starts from position (0,0).

g = 9.8;
v0 = 30;
a = pi/2.5;
r = 200;

%Tend it the end time (two times the time it takes for
%the projectile to reach its maximum height, where the velocity
%in the y-direction is zero)
%deltaT is the time step

Tend = 2*v0*sin(a)/g;
deltaT = Tend/r;

%t time vector 
%x vector of x-coordinates
%y vector of y-coordinates

t = 0:deltaT:Tend;
x = v0*cos(a)*t;
y = -g/2*t.^2+v0*sin(a)*t;

figure(1)
 
for s=1:r+1
    plot(x(s),y(s),'o','MarkerFaceColor', 'r','MarkerSize',8);
    axis([0 80 0 80])
    drawnow
end
