function [x, y, vx, vy, t] = solveproj(tf, dt, x0, y0, vx0, vy0)
%SOLVEPROJ Numerical solution for projectile motion
%   [X, Y, VX, VY, T] = SOLVEPROJ(TF, DT, X0, Y0, VX0, VY0)
%   solves the projectile motion problem for a projectile
%   having initial location (X0, Y0) moving with initial
%   velocity (VX0, VY0) over the time period [0, TF] in
%   time steps of DT.
%
%   The position (X, Y) and velocity (VX, VY) of the
%   projectile is evaluated at times T.

t = 0:dt:tf;
% make sure tf is at the end of t
if t(end) ~= tf
    t = [t tf];
end
n = length(t);

% estimated position and velocity
x = zeros(size(t));
y = zeros(size(t));
vx = zeros(size(t));
vy = zeros(size(t));
x(1) = x0;
y(1) = y0;
vx(1) = vx0;
vy(1) = vy0;
for i = 2:n
    x(i) = x(i - 1) + vx(i - 1) * dt;
    y(i) = y(i - 1) + vy(i - 1) * dt;
    vx(i) = vx(i - 1);
    vy(i) = vy(i - 1) - 9.81 * dt;
end
