% PEng 2.10

% Gravity
g = -9.81; % m/s^2

% Time steps
t = 0:0.05:10; % s

% Ask user for input
h0 = input('Give initial height above ground in m: ');
v0 = input('Give initial vertical velocity in m/s (upward = positive): ');

% Height, velocity over time
h = 1/2*g*t.^2 + v0*t + h0;
v = g*t + v0;

endstep = find(h < 0);  

figure(1)
clf

subplot(2,1,1)
plot(t(1:(endstep(1) - 1)),h(1:(endstep(1) - 1)))
xlabel('time [s]')
ylabel('height above ground [m]')

subplot(2,1,2)
plot(t(1:(endstep(1) - 1)),v(1:(endstep(1) - 1)))
xlabel('time [s]')
ylabel('vertical velocity [m/s]')

