%MATLAB code for finding maximum height
% Example from Chapter 1 
% Definiton of input variables
t = 0;          % Initial time
h = 0;          % Initial height
t_new = 0;      % new time
h_new = 0;      % new height
delta_t = .1;  % Time step
v = 10;         % Inital speed
theta = 35;     % Launch angle
g = 9.81;       % Gravitational constant
% Check for decreasing height
% While the new height is >= current height
while h_new >= h;
    h = h_new;  % Currrent height is now new height
    t = t_new;  % Current time is now new time
    % Take one time step
    t_new = t + delta_t;  % new time is time + delta time
    % Calculate height per Eq. 1.1
    h_new = v*t_new*sind(theta)-0.5*g*t_new^2;
end;
% Output maximum height
h_max = h
