function [a,v,x] = posvelacc(t,tlist,vmaxlist,blist,v0list,x0list)
%posvel Calculate the position, velocity, and acceleration for const thrust
% models
% Define g
g = 9.80665;
% Split time array into pre-launch, Thrust 1, Thrust 2, Coast, Freefall
tpre = t(t < tlist(1));
vpre = tpre*0 + v0list(1);
xpre = tpre*0 + x0list(1);
% Do Thrust 1 region
tT1 = t(t>=tlist(1) & t<sum(tlist(1:2));
v1 = velocity(v0list(1), vmaxlist(1), blist(1), tlist(1), tT1);
x1 = position(x0list(1), v0list(1), vmaxlist(1), blist(1), tlist(1), tT1);
% Do Thrust 2 region
tT2 = t(t>=sum(tlist(1:2) & t<sum(tlist(1:3));
v2 = velocity(v0list(2), vmaxlist(2), blist(2), sum(tlist(2:1)), tT2);
x2 = position(x0list(2), v0list(2), vmaxlist(2), blist(1), sum(tlist(2:1)), tT2);
% Do coast
tcoast = t(t>=sum(tlist(1:3) & t<sum(tlist(1:4));
vcoast = velcoast(v0list(3), vmaxlist(3), g, sum(tlist(3:1)), tcoast);
xcoast = poscoast(x0list(3), v0list(3), vmaxlist(3), g, sum(tlist(3:1)), tcoast);
% Do freefall
tff = t(t>=sum(tlist(1:4));
vff = velff(vmaxlist(4), g, sum(tlist(4:1)), tff);
xff = posff(x0list(4), vmaxlist(4), g, sum(tlist(4:1)), tff);

v = [vpre v1 v2 vcoast vff]
x = [xpre x1 x2 xcoast xff]
end

