%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% numpkm11 %%%%%%%%%%
%
% % Exercise 2.10 Chapman (version 2)
%
% % author: Davoud Saffar
%
% % created: 11/12/04
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



clc, clear all, close all

h0 = input('Initial height: ');
v0 = input('Initial velocity: ');

g = -9.81;
t = 0;
T = [];

h = h0;
H = [];
V = [];

tstep = .1;

while(h>0)
    h = (1/2)*g*t^2+v0*t+h0;
    v = g*t+v0;
     if(h<=0)
         break
     end
    
    H = [H h];
    V = [V v];
    T = [T t];
    
    plot(t,h,'*',t,v,'o')
    title('position and velocity of a falling ball ')
    xlabel('time [s]')
    ylabel('h,v')
    legend('Position','Velocity') %%legends for functions or curves
    hold on %%holds the currunt graph
    grid on
    
    t = t+tstep;
end


%figure
%plots two functions with the same x axis and two different y axes
%plotyy(x,y1,x,y2)
%plotyy(T,H,T,V)
%grid on


%figure
%for cnt =1:numel(H)
%    plot(H(cnt),'o')
%    axis([0 2 -0.5 max(H)+1]) %set axis scaling
%    title(num2str(V(cnt)))   %number to string
%    ylabel('height')
%    pause(.3)
%end




















