Hi Garrett,
As per my understanding, you want to plot the range vs altitude plot of a model rocket. However, there is a huge drift in the range of the model during the descent phase of the rocket.
Upon reviewing the code, I noticed that there is an issue with how the force is being applied to the model rocket. To ensure the range of the rocket is accurate, you may revisit the following points.
- Gravity should only influence the vertical component of the rocket's velocity.
- The thrust should impact both the vertical and horizontal components of the rocket's velocity.
- During the descent phase, the horizontal component of the velocity should remain constant as there are no forces acting in that direction.
Please consider the modifications to the 'dv' and 'dvx' variables for different phases, in the code snippet below.
% burn phase
dv = (thrust(time)/mass)*cosd(launch_angle)*dt - (D/mass)*dt - 9.81*dt;
dvx = (thrust(time)/mass)*sind(launch_angle)*dt;
% coast phase
dv = (D/mass)*dt - 9.81*dt;
dvx = 0;
% descent phase
dv = (D/mass)*dt - 9.81*dt;
dvx = 0;
Hope this helps!