function x = poscoast(x0, v0, vt, g, t0, t)
%poscoast calculates the altitude from burnout to apogee
%   x0 is the initial altitude at burnout.
%   v0 is the initial velocity at burnout.
%   vt is the terminal velocity.
%   g is the local acceleration of gravity.
%   t0 is the time at which the coasting phase began.
%   t is the array of times for which the coasting velocity is desired.
x = x0 + vt*vt/g*(log(cos(g/vt*(t-t0)-atan(v0/vt))) ...
    +log(sqrt(1+v0*v0/vt/vt)));
end

