function x = position(x0, v0, vmax, b, t0, t)
%position calculates the position or altitude from ignition to burnout and
% from apogee onward. Use poscoast to calculate from burnout to apogee.
%   x0 is the initial altitude for this phase.
%   v0 is the initial velocity for this phase.
%   vmax is the maximum or terminal velocity for this phase.
%   b is the b term in the equations. It's -g for descent.
%   t0 is the time at which the calculated phase begins.
%   t is the array of times for which the velocity is desired.
if vmax > v0
    x = x0 + vmax*vmax/b*(log(cosh(b/vmax*(t-t0)+atanh(v0/vmax)))-log(cosh(atanh(v0/vmax))));
else
    x = x0 + vmax*vmax/b*(log(sinh(b/vmax*(t-t0)+acoth(v0/vmax)))-log(sinh(acoth(v0/vmax))));
end