% testParabolicTrajectory.m
% Calls parabolicTrajectory to find a gravitational trajectory.
% Then derives it twice to calculate the velocity and the acceleration,
% and compares them with the known analytic formulae.
% J.M.Soler. Sept.2011

% Set initial conditions
clear
t = 0 : 0.05 : 2;   % times, in s
x0 = 0; y0 = 15;    % initial position, in m
v0x = 3; v0y = 5;   % initial velocity, in m/s
g = 9.81;           % gravitational acceleration, in m/s^2

% Find trajectory
[x,y] = parabolicTrajectory(x0,y0,v0x,v0y,t);

% Find velocity
vx = derivative(t,x);
vy = derivative(t,y);

% Find acceleration
ax = derivative(t,vx);
ay = derivative(t,vy);

% Plot velocity, using thick lines and large fornts and symbols
figure(1)
plot(t,vx,t,v0x+0*t,'o', t,vy,t,v0y-g*t,'o','LineWidth',1.5,'MarkerSize',10)
legend('vx numerical','vx analytic','vy numerical','vy analytic')
xlabel('time (s)'), ylabel('velocity (m/s)')
set(gca,'FontSize',15)
grid on

% Plot acceleration
figure(2)
plot(t,ax,t,0*t, t,ay,t,-g+0*t,'LineWidth',1.5)
legend('ax numerical','ax analytic','ay numerical','ay analytic')
xlabel('time (s)'), ylabel('acceleration (m/s^2)')
set(gca,'FontSize',15)
grid on
