%**************************************************************************
% debugthis.m
%
% PROGRAM DESCRIPTION
% The following program uses simple kinematic relationships to solve for 
% the instantaneous location of a two-dimensional trajectory with time.
%
% Inputs:
% V_launch - launch speed of projectile in m/s
% angle    - launch angle of projectile in degrees
%
% Outputs:
% x_instant - instantaneous horizontal displacement in m
% y_instant - instantaneous vertical displacement in m
%
% Written by: Joe Smith
% Written on: December 6, 2012
%**************************************************************************
clc
clear variables

%% Initialize problem parameters
V_launch = 80.0;  % launch speed in m/s
angle    = 50.0;  % launch angle in degrees
gravity  = 9.81;  % gravitational acceleration in m/s/s

%% Define initial horizontal and vertical velocities
u_init = V_launch * cos(theta);  % in m/s
v_init = v_launch * sin(theta);  % in m/s

%% Initialize looping variable
t_start = 0.0;   % start time in seconds
delta_t = 1.0;   % time increment in seconds
t_end   = 20.0;  % end time in seconds

%% Print out table header
fprintf('Flight time (s)   x-position (m)    y-position (m)\n');
fprintf('---------------   --------------    --------------\n');

%% Compute instantaneous displacement in horizontal and vertical directions
for t = t_strat:delta_t:t_end
    x_instant = u_init * t;                         % in meters
    y_instant = v_init * t + 0.5 * gravity * t^2;   % in meters
    v_instant = v_init - gravity * t;               % in m/s
    fprintf(file_num, ' %10.2f      %10.2f ', t, x_instant, y_instant);
end