function [vmax,apogee,tapogee] = VmaxApogee(BurnTime, ...
    T, mlist, CD, Ap, rho)
%makelists Create the lists of transitions and initial conditions
%   The functions used on each part of the flight change with each
%   transition. The regions are, Pre-launch, initial thrust, final thrust,
%   coast to apogee, parachute descent from apogee. CDp and App are for the
%   parachute. For free fall (ballistic descent) make them the same as for
%   the thrust and coasting phase.
% For the numbering of parameters:
% 1 = pre-launch
% 2 = thrust
% 3 = coast to apogee
% 4 = post-apogee

gloc = 9.80665; % local acceleration of gravity in m/s^2

t0list(1) = 0 - 100; % Start of pre-launch, not actually used in calculations
t0list(2) = 0; % End of pre-launch, start of thrust
t0list(3) = t0list(2) + BurnTime; % End of thrust, start of coast 

vmaxlist(1) = 0; % pre-launch
vmaxlist(2) = sqrt(2*(T- mlist(2)*gloc)/(rho*CD*Ap));
vmaxlist(3) = sqrt((2*mlist(4)*gloc)/(rho*CD*Ap)); % Terminal Velocity

blist(1) = -gloc;
blist(2) = (T/mlist(2) - gloc);
blist(3) = gloc;

v0list(1) = 0;
v0list(2) = 0;
v0list(3) = velocity(v0list(2), vmaxlist(2), blist(2), 0, BurnTime);
v0list(4) = 0; % vapogee = 0 by definition
vmax = v0list(3);

tapogee = vmaxlist(3)/gloc*atan(v0list(3)/vmaxlist(3)); % length of stage 3
t0list(4) = t0list(3) + tapogee; % Start of descent from apogee
tapogee = t0list(4);

x0list(1) = 0;
x0list(2) = 0;
x0list(3) = position(x0list(2), v0list(2), vmaxlist(2), blist(2), 0, BurnTime);
x0list(4) = vmaxlist(3)^2/gloc*log(sqrt(1+v0list(3)^2/vmaxlist(3)^2))+x0list(3);
apogee = x0list(4);


end

